forked from chenshuxian/DNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
95 lines (87 loc) · 2.33 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var gulp = require('gulp'),
nodemon = require('gulp-nodemon');
// plumber = require('gulp-plumber'),
var gutil = require('gulp-util'),
webpack = require("webpack"),
webpackDevConfig = require("./webpackDev.config.js"),
webpackConfig = require("./webpack.config.js"),
livereload = require('gulp-livereload'),
sass = require('gulp-ruby-sass');
gulp.task("webpackDev", function(callback) {
// run webpack
var myConfig = Object.create(webpackDevConfig);
webpack(myConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("webpack", function(callback) {
// run webpack
var myConfig = Object.create(webpackConfig);
webpack(myConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
colors: true
}));
callback();
});
});
var myDevConfig = Object.create(webpackDevConfig);
myDevConfig.debug = true;
var devCompiler = webpack(myDevConfig);
gulp.task("webpack:build-dev", function(callback) {
// run webpack
devCompiler.run(function(err, stats) {
if (err) throw new gutil.PluginError("webpack:build-dev", err);
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
livereload({start: true});
callback();
});
});
gulp.task('sass', function() {
return sass('./public/css/**/*.scss')
.pipe(gulp.dest('./public/css'))
.pipe(livereload());
});
gulp.task('jade', function() {
livereload();
});
gulp.task('watch', function() {
gulp.watch('./public/css/*.scss', ['sass']);
gulp.watch('./public/js/*.js', ['webpack:build-dev']);
gulp.watch('./app/views/*.jade', ['jade']);
livereload.listen();
});
gulp.task('develop', function() {
// livereload.listen();
nodemon({
script: 'app.js',
ext: 'js coffee jade',
stdout: false
}).on('readable', function() {
this.stdout.on('data', function(chunk) {
if (/^Express server listening on port/.test(chunk)) {
livereload.changed(__dirname);
}
});
this.stdout.pipe(process.stdout);
this.stderr.pipe(process.stderr);
});
});
gulp.task('dev', [
'sass',
'develop',
'watch',
'webpackDev'
]);
gulp.task('default', [
'sass',
'develop',
'watch',
'webpack'
]);