-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
72 lines (62 loc) · 2.32 KB
/
gulpfile.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
'use strict';
const gulp = require('gulp'),
runSequence = require('run-sequence'),
del = require('del'),
open = require('open'),
named = require('vinyl-named'),
connect = require('gulp-connect'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cleanCss = require('gulp-clean-css'),
plumber = require('gulp-plumber'),
changed = require('gulp-changed'),
gulpIf = require('gulp-if'),
webpackStream = require('webpack-stream'),
webpack = require('webpack'),
isDev = process.argv.indexOf('--dev') > -1,
paths = require('./config/paths'),
webpackConfig = isDev ? require('./config/webpack.config.dev') : require('./config/webpack.config.prod'),
connectConfig = require('./config/connect.config'),
sassConfig = require('./config/sass.config'),
autoprefixerConfig = require('./config/autoprefixer.config');
gulp.task('clean', () => del(paths.dist.root));
gulp.task('open', () => open('http://localhost:' + connectConfig.port));
gulp.task('serve', () => connect.server(connectConfig));
gulp.task('webpack', () => {
return gulp.src(paths.src.files.jsEntry)
.pipe(plumber())
.pipe(named())
.pipe(webpackStream(webpackConfig, webpack))
.pipe(gulp.dest(paths.dist.js))
.pipe(connect.reload());
});
gulp.task('sass', () => {
return gulp.src(paths.src.files.sass)
.pipe(plumber())
.pipe(gulpIf(isDev, sourcemaps.init()))
.pipe(sass.sync(sassConfig))
.pipe(autoprefixer(autoprefixerConfig))
.pipe(gulpIf(!isDev, cleanCss()))
.pipe(gulpIf(isDev, sourcemaps.write('.')))
.pipe(gulp.dest(paths.dist.css))
.pipe(connect.reload());
});
gulp.task('html', () => {
return gulp.src(paths.src.files.html)
.pipe(plumber())
.pipe(changed(paths.dist.root))
.pipe(gulp.dest(paths.dist.root))
.pipe(connect.reload());
});
gulp.task('watch', () => {
gulp.watch(paths.src.files.js, ['webpack']);
gulp.watch(paths.src.files.sass, ['sass']);
gulp.watch(paths.src.files.html, ['html']);
});
gulp.task('build', callback => {
runSequence(['webpack', 'sass', 'html'], callback);
});
gulp.task('default', callback => {
runSequence('clean', 'build', 'serve', 'watch', 'open', callback);
});