-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathgulpfile.js
104 lines (82 loc) · 2.56 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
96
97
98
99
100
101
102
103
var gulp = require('gulp'),
path = require('path'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
webpack = require('webpack'),
babelLoader = require('babel-loader');
var BUILD = process.env.NODE_ENV === 'production';
if( ! BUILD ) {
var browserSync = require('browser-sync').create(),
reload = browserSync.reload,
nodemon = require('nodemon');
}
gulp.task('default',['serve'],function() {});
gulp.task('build',['sass','webpack'],function() { return gutil.log("Completed"); });
gulp.task('webpack',function(callback) {
var init = false;
webpack({
entry : './static/js/index.js',
output : {
publicPath: '/dist/js/',
path : path.join(__dirname, 'static/dist/js'),
filename : 'bundle.js'
},
watch : !BUILD,
devtool : BUILD ? '' : '#source-map',
resolve : {
alias : {
fs : 'browserify-fs'
}
},
node : {
process: true
},
module : {
loaders : [
{ test: /\.js$/, loader: 'babel-loader', exclude: /(node_modules)/ }
]
},
plugins : BUILD ? [ new webpack.optimize.UglifyJsPlugin({ sourceMap: false }) ] : []
}, function( err, stats ) {
if(err) throw new gutil.PluginError('webpack',err);
var jsonStats = stats.toJson();
if(jsonStats.errors.length > 0)
jsonStats.errors.forEach(function(error) {
gutil.log(gutil.colors.magenta('webpack'),gutil.colors.bold.red('error'),error);
});
if(jsonStats.warnings.length > 0)
jsonStats.warnings.forEach(function(warning) {
gutil.log(gutil.colors.magenta('webpack'),gutil.colors.bold.yellow('warning'),warning);
});
if(!BUILD) reload();
if(!init) { callback(); init = true; }
});
});
gulp.task('sass',function() {
var stream = gulp.src('./static/sass/**/*.scss')
.pipe(sass({
outputStyle : BUILD ? 'compressed' : 'nested'
})).on('error', sass.logError)
.pipe(gulp.dest('./static/style'));
if(!BUILD) return stream.pipe(reload({stream:true}));
else return stream;
});
gulp.task('serve',['nodemon','webpack'],function() {
browserSync.init(null,{
proxy : 'http://localhost:3000',
port : 7000
});
gulp.watch('static/sass/**/*.scss',['sass']);
gulp.watch(["static/index.html"]).on("change",reload);
});
gulp.task('nodemon',function(cb) {
var init = true;
nodemon({
script: 'app.js',
watch: ['app.js']
}).on('start', function() {
if(init) cb(); // Only call cb once when server is started initially.
setTimeout(function() { reload(); },1000);
init = false;
});
});