-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
78 lines (65 loc) · 2.03 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
73
74
75
76
77
78
'use strict';
const gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
sass = require('gulp-sass'),
sassImporter = require('sass-module-importer'),
rename = require('gulp-rename'),
del = require('del'),
webpack = require('webpack'),
through = require('through2'),
scssToJson = require('scss-to-json'),
webpackConfig = require('./webpack.config');
const paths = {
js: 'src/js/**/*.js',
sass: 'src/sass/**/*.scss'
};
gulp.task('variables', () => {
return gulp.src('src/sass/variables.scss', { read: false })
.pipe(through.obj((file, enc, cb) => {
const variables = scssToJson(file.path);
file.contents = new Buffer(JSON.stringify(variables));
cb(null, file);
}))
.pipe(rename('variables.json'))
.pipe(gulp.dest('src/shared'));
});
const compiler = webpack(webpackConfig);
const webpackCompileHandler = (cb, watching) => {
return (err, stats) => {
console.log(`Webpack: ${stats}`);
if (err) return cb(err);
if (!watching) cb();
};
};
gulp.task('compile-js', cb => {
if (process.env.NODE_ENV === 'development') {
return compiler.watch({
ignored: /node_modules/
}, webpackCompileHandler(cb, true));
}
compiler.run(webpackCompileHandler(cb));
});
gulp.task('build-js', gulp.series('variables', 'compile-js'));
gulp.task('build-css', () => {
return gulp.src(paths.sass, { sourcemaps: true })
.pipe(sass({ importer: sassImporter() }).on('error', sass.logError))
.pipe(gulp.dest('public/css'));
});
gulp.task('clean-css', () => del(['public/css']));
gulp.task('clean', gulp.series('clean-css'));
gulp.task('watch', () => {
// Webpack has its own watch
gulp.watch(paths.sass, gulp.series('clean-css', 'build-css'));
});
const nodemonConfig = {
script: 'server.js',
ext: 'js',
watch: ['lib'],
env: { NODE_ENV: 'development' },
nodeArgs: []
};
gulp.task('serve', () => {
nodemon(nodemonConfig);
});
gulp.task('build', gulp.series('clean', gulp.parallel('build-js', 'build-css')));
gulp.task('default', gulp.parallel('build', 'serve', 'watch'));