-
Notifications
You must be signed in to change notification settings - Fork 135
/
dev-server.js
42 lines (35 loc) · 1.07 KB
/
dev-server.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
var devConfig = require('./webpack.local.config');
ensureBuildExists();
// Start webpack:
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var compiler = webpack(devConfig);
new WebpackDevServer(compiler, {
publicPath: devConfig.output.publicPath,
contentBase: "./build",
disableHostCheck: true,
hot: true,
quiet: false,
filename: 'app.js',
stats: { colors: true },
noInfo: false,
historyApiFallback: true
}).listen(devConfig.port, '0.0.0.0', function (err) {
if (err) {
console.log(err);
} else {
console.log('Dev Server listening at http://127.0.0.1:' + devConfig.port);
}
});
function ensureBuildExists() {
var fs = require('fs');
var path = require('path');
var buildDir = path.join(__dirname, 'build');
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir);
}
var source = path.join(__dirname, 'src', 'index.html');
var dest = path.join(__dirname, 'build', 'index.html');
console.log('Copying ' + source + ' to ' + dest);
fs.createReadStream(source).pipe(fs.createWriteStream(dest));
}