forked from AMar4enko/ionic-webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
115 lines (99 loc) · 3.25 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
104
105
106
107
108
109
110
111
112
113
114
var gulp = require("gulp");
var gutil = require('gulp-util');
var webpack = require("webpack");
var ngAnnotateWebpackPlugin = require("ng-annotate-webpack-plugin");
var WebpackDevServer = require("webpack-dev-server");
var webpackConfig = require("./webpack.config.js");
var argv = require('yargs').argv;
argv.env = argv.env || 'development';
var src = './src',
dest = './dist',
webpackOptions = {
debug: true,
devtool: '#source-map',
watchDelay: 200
};
// The development server (the recommended option for development)
gulp.task("default", ["webpack-dev-server"]);
// Build and watch cycle (another option for development)
// Advantage: No server required, can run app from filesystem
// Disadvantage: Requests are not blocked until bundle is available,
// can serve an old app on refresh
gulp.task("build-dev", ["webpack:build-dev"], function() {
gulp.watch(["src/**/*"], ["webpack:build-dev"]);
});
// Production build
gulp.task("build", ["webpack:build"]);
gulp.task("webpack:build", function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
if(argv.env != 'development'){
myConfig.plugins = myConfig.plugins.concat(
new ngAnnotateWebpackPlugin({
add: true
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
output: {comments: false}
})
);
}
// run webpack
webpack(myConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack:build", err);
gutil.log("[webpack:build]", stats.toString({
colors: true
}));
callback();
});
});
// modify some webpack config options
var myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = "sourcemap";
myDevConfig.debug = true;
// create a single instance of the compiler to allow caching
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
}));
callback();
});
});
gulp.task("webpack-dev-server", function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: "/www",
inline: true,
hot: true,
stats: {
colors: true
}
}).listen(5000, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:5000/webpack-dev-server/index.html");
});
});
gulp.task("webpack-test-server", function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.debug = false;
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: "/",
inline: true,
stats: {
colors: true
}
}).listen(5000, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:5000/webpack-dev-server/index.html");
});
});