-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
51 lines (44 loc) · 1.51 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var webpack = require('webpack');
var webpackConfig = require('./webpack.config.js');
gulp.task('default', ['build']);
gulp.task('build-dev', ['webpack:build-dev'], function () {
gulp.watch(['src/**/*'], ['webpack:build-dev']);
});
gulp.task('build', ['webpack:build']);
gulp.task('webpack:build', function (callback) {
var myConfig = Object.create(webpackConfig);
myConfig.plugins = myConfig.plugins || [];
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
webpack(myConfig, function (err, stats) {
if (err) throw new gutil.PluginError('webpack:build', err);
gutil.log('[webpack:build]', stats.toString({
colors: true
}));
callback();
});
});
gulp.task('webpack:build-dev', function (callback) {
var myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = 'source-map';
// create a single instance of the compiler to allow caching
var devCompiler = webpack(myDevConfig);
// 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
}));
callback();
});
});