-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
executable file
·81 lines (68 loc) · 2.02 KB
/
gulpfile.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import gulp from 'gulp';
import connect from 'gulp-connect'; // Pokrece lokalni dev server
import open from 'gulp-open'; // Otvara URL u web browseru
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import concat from 'gulp-concat';
import eslint from 'gulp-eslint';
const config = {
port: 9000,
devBaseUrl: 'http://localhost',
paths: {
html: './src/*.html',
images: './src/images/*',
dist: './dist',
js: ['./src/**/*.js', './src/**/*.jsx'],
mainJs: './src/main.jsx',
css: [
'./src/css/style.css',
],
},
};
// Pokrece lokalni dev server
gulp.task('connect', () => {
connect.server({
root: ['dist'],
port: config.port,
base: config.devBaseUrl,
livereload: true,
});
});
gulp.task('open', ['connect'], () => {
gulp.src('dist/index.html').pipe(open({ uri: `${config.devBaseUrl}:${config.port}/` }));
});
gulp.task('watch', () => {
gulp.watch(config.paths.html, ['html']);
gulp.watch(config.paths.js, ['js']);
gulp.watch(config.paths.css, ['css']);
});
gulp.task('html', () => {
gulp.src(config.paths.html)
.pipe(gulp.dest(config.paths.dist))
.pipe(connect.reload());
});
gulp.task('css', () => {
gulp.src(config.paths.css)
.pipe(concat('bundle.css'))
.pipe(gulp.dest(`${config.paths.dist}/css`));
});
gulp.task('images', () => {
gulp.src(config.paths.images)
.pipe(gulp.dest(`${config.paths.dist}/images`));
});
gulp.task('js', () => {
browserify(config.paths.mainJs, { extensions: ['.jsx'] })
.transform(babelify, { presets: ['es2015', 'react', 'stage-0'] }).bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest(`${config.paths.dist}/scripts`))
.pipe(connect.reload());
});
gulp.task('lint', () => {
gulp.src(config.paths.js)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('default', ['html', 'lint', 'images', 'css', 'js', 'open', 'watch']);