-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.server.js
70 lines (46 loc) · 1.38 KB
/
webpack.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Webpack Server Configuration
===================================================================================================================== */
// Load Core:
const fs = require('fs');
const webpack = require('webpack');
// Load Server:
const WebpackDevServer = require('webpack-dev-server');
// Load Config:
const config = require('./webpack.config.js')();
// Define Server:
const SERVER = {
HOST: 'localhost',
PORT: 8080,
HTTPS: false
};
// Define Server Protocol:
const SERVER_PROTOCOL = SERVER.HTTPS ? 'https' : 'http';
// Define Server URL:
const SERVER_URL = `${SERVER_PROTOCOL}://${SERVER.HOST}:${SERVER.PORT}`;
// Define Options:
const options = {
hot: true,
host: SERVER.HOST,
port: SERVER.PORT,
https: SERVER.HTTPS,
stats: {
colors: true
},
headers: {
'Access-Control-Allow-Origin': '*'
},
publicPath: `${SERVER_URL}/production`
};
// Override Output Public Path:
config.output.publicPath = options.publicPath;
// Add Entrypoints:
WebpackDevServer.addDevServerEntrypoints(config, options);
// Create Compiler Instance:
const compiler = webpack(config);
// Create Server Instance:
const server = new WebpackDevServer(compiler, options);
// Begin Listening:
server.listen(port = SERVER.PORT, host = SERVER.HOST, (error) => {
if (error) return console.log(error);
console.log(`Development server listening on ${SERVER_URL}...`);
});