-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
93 lines (78 loc) · 2.55 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
var gulp = require('gulp');
var path = require('path');
var gutil = require('gulp-util');
var merge = require('merge-stream');
var webpack = require("webpack");
var assign = require('lodash/assign');
var WebpackDevServer = require("webpack-dev-server");
// By default run a server for development
gulp.task("default", ["webpack-dev-server"]);
// Production build
gulp.task("build", ["webpack:build"]);
// Production build
gulp.task("webpack:build", function(callback) {
// modify some webpack config options
process.env.NODE_ENV = "production"
var buildConfig = Object.create(getWebpackConfig());
buildConfig.plugins = buildConfig.plugins.concat(
new webpack.optimize.UglifyJsPlugin()
);
// run webpack
webpack(buildConfig, 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) {
process.env.NODE_ENV = "production"
var devAccountConfig = Object.create(getWebpackConfig());
devAccountConfig.devtool = "sourcemap";
// devAccountConfig.debug = true;
// create a single instance of the compiler to allow caching
var devCompiler = webpack(devAccountConfig);
devCompiler.run(function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("webpack-dev-server", function(callback) {
// Start a webpack-dev-server
var serverConfig = Object.create(getWebpackConfig());
// var entry = {}
// Object.keys(serverConfig.entry).forEach( function( key ) {
// entry[key] = ["webpack/hot/dev-server", serverConfig.entry[key]];
// });
// serverConfig.entry = entry;
// serverConfig.devtool = "sourcemap"; //"eval" for performance, but no JSX :(
// serverConfig.debug = true;
new WebpackDevServer(webpack(serverConfig), {
publicPath: serverConfig.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true
},
disableHostCheck: true,
}).listen(8085, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
// Server listening
gutil.log("[webpack-dev-server]", "http://localhost:8085/webpack-dev-server/index.html");
// keep the server alive or continue?
// callback();
});
});
function getWebpackConfig() {
var entries = {
"demo": "./client/demo.js"
};
// clone and extend webpackConfig
var customConfig = Object.create(require("./webpack.config.js"));
customConfig.entry = entries;
return customConfig;
}