-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
48 lines (37 loc) · 1.24 KB
/
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
43
44
45
46
47
48
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
var serverConfig = require('./server.config.json');
var devServerPort = serverConfig.devServerPort || 8080;
var contentUrl = serverConfig.url;
var compiler = webpack(config);
var originalOutputFileSystem = compiler.outputFileSystem;
module.exports.start = function start(callback) {
var devServer = new WebpackDevServer(compiler, {
contentBase: contentUrl,
//hot: true,
//headers: { "Access-Control-Allow-Origin": "*" },
inline: true,
historyApiFallback: true,
filename: config.output.filename
})
.listen(devServerPort, 'localhost', function (err, result) {
// WebpackDevServer uses in-memory compilation
// (!) Restore original output to file system
compiler.outputFileSystem = originalOutputFileSystem;
if (err) {
console.error(err);
return callback(err);
}
console.log('Listening to localhost:' + devServerPort);
callback(null, devServer);
});
};
module.exports.build = function build(callback){
compiler.run(function(err, stats) {
if(err)
console.error(stats);
if(stats) console.info(stats.toString());
callback(err, stats);
});
}