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
|
var path = require('path');
var del = require('del');
var gulp = require('gulp');
var gutil = require('gulp-util');
var webpack = require('webpack');
var argv = require('yargs').argv;
var output = argv.output || path.join(__dirname, 'src/main/webapp');
var styles = require('./gulp/styles').styles;
var webpackConfig = require('./webpack.config.js');
webpackConfig.output.path = path.join(output, 'js/bundles');
// Clean
gulp.task('clean', function (done) {
del([
path.join(output, 'js'),
path.join(output, 'css')
], done);
});
// Styles
gulp.task('styles:prod', function () {
return styles(output, true);
});
gulp.task('styles:dev', function () {
return styles(output, false, true);
});
// Webpack
gulp.task('webpack:prod', function (callback) {
var webpackProdConfig = Object.create(webpackConfig);
webpackProdConfig.plugins = webpackProdConfig.plugins.concat(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
'OUTPUT': output
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
webpack(webpackProdConfig, function (err) {
if (err) {
throw new gutil.PluginError('webpack:prod', err);
}
callback();
});
});
gulp.task('webpack:dev', function (callback) {
// run webpack
webpack(webpackConfig, function (err) {
if (err) {
throw new gutil.PluginError('webpack:dev', err);
}
callback();
});
});
// Tasks
gulp.task('build', ['clean', 'styles:prod', 'webpack:prod']);
gulp.task('build:dev', ['clean', 'styles:dev', 'webpack:dev']);
gulp.task('default', ['build']);
|