-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
58 lines (55 loc) · 1.92 KB
/
Copy pathrunner.js
File metadata and controls
58 lines (55 loc) · 1.92 KB
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
let packageJson = require("./package.json");
let webpack = require("webpack");
let webpackConfig = require("./webpack.config");
let WebpackDevServer = require("webpack-dev-server");
let args = process.argv.slice(2);
const PORT = process.env.PORT || 3700;
/**
*
* @param {Array<string>} args
*/
function ExecuteApp(args) {
if (args[0] == 'debug') {
const config = webpackConfig(true, 'dist', PORT);
const options = {
contentBase: `./dist`,
watchOptions: {
aggregateTimeout: 100
},
stats: {
colors: true
},
hot: true, // Live-reload
inline: true,
watchContentBase: true,
publicPath: config.output.publicPath,
host: 'localhost'
};
WebpackDevServer.addDevServerEntrypoints(config, options)
return new WebpackDevServer(webpack(config), options)
.listen(PORT, 'localhost', (err) => {
if (err) throw new console.error('webpack-dev-server\n ' + err);
console.log(`[${packageJson.name} serve]`, `Listening at http://127.0.0.1:${PORT}`);
});
} else if (args[0] == 'prod') {
const config = webpackConfig(false, 'build');
webpack(config, (err, stats) => {
if (err) throw new console.error('build\n ', err);
console.log(`[${packageJson.name} build]`, stats.toString({
colors: true
}));
});
} else if (args[0] == 'watch') {
let config = webpackConfig(true, 'dist', PORT);
console.log('[Watch started]');
webpack(config).watch({
aggregateTimeout: 100
}, (err, stats) => {
if (err) throw new console.error('watch\n ', err);
console.log(`[${packageJson.name} Watching...]`, stats.toString({
colors: true
}));
});
}
}
ExecuteApp(args);