-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
62 lines (52 loc) · 1.93 KB
/
server.js
File metadata and controls
62 lines (52 loc) · 1.93 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
59
60
61
62
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.buildPathDestination =
process.env.npm_lifecycle_event === 'build' ?
serverConfig.buildFolder : serverConfig.deployFolder;
module.exports.deployPathDestination = serverConfig.deployFolder;
module.exports.start = function start(callback) {
var devServer = new WebpackDevServer(compiler, {
contentBase: contentUrl,
//hot: true,
headers: {
"Access-Control-Allow-Origin": "*"
//"Access-Control-Allow-Origin": "http://localhost:4848",
//"Access-Control-Allow-Credentials": true,
// "Access-Control-Allow-Origin": "http://localhost:4848",
// "Access-Control-Allow-Credentials": true,
// "Origin": "http://localhost:4848"
// http://localhost:4848
// "Origin": "http://localhost:4848",
// "Access-Control-Allow-Credentials": true,
// "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
},
// inline: true,
historyApiFallback: true,
filename: config.output.filename
})
.listen(devServerPort, 'localhost', function (err, result) {
// WebpackDevServer uses in-memory compilation
// (!) Restore original output file system
compiler.outputFileSystem = originalOutputFileSystem;
if (err) {
console.error(err);
return callback(err);
}
console.log('Listening at 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);
});
}