-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathserver.js
38 lines (33 loc) · 936 Bytes
/
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
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const openInEditor = require('express-open-in-editor');
const sourceFragment = require('express-source-fragment');
const config = require('./webpack.config');
const PORT = process.env.PORT || 3000;
const options = {
publicPath: config.output.publicPath,
contentBase: '.',
hot: true,
host: 'localhost',
historyApiFallback: true,
stats: {
colors: true
},
before(app) {
app.use('/open-in-editor', openInEditor({
cwd: __dirname
}));
app.use('/source-fragment', sourceFragment({
cwd: __dirname
}));
}
};
WebpackDevServer.addDevServerEntrypoints(config, options);
const compiler = webpack(config);
const server = new WebpackDevServer(compiler, options);
server.listen(PORT, 'localhost', function(err) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:' + PORT);
});