-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (27 loc) · 1014 Bytes
/
Copy pathserver.js
File metadata and controls
31 lines (27 loc) · 1014 Bytes
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
const dotenv = require('dotenv');
const path = require('path');
const Webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
const devcert = require('devcert');
dotenv.config();
const LOCALHOST = process.env.HOST_NAME ? process.env.HOST_NAME : 'localhost'
const PORT = process.env.PORT ? process.env.PORT : 3000;
async function startServer(options) {
if(process.env.USE_HTTPS === 'yes') {
const ssl = await devcert.certificateFor(LOCALHOST, { skipCertutilInstall: false, skipHostsFile: false });
options.public = LOCALHOST;
options.https = { ...ssl };
}
WebpackDevServer.addDevServerEntrypoints(config, options);
const compiler = Webpack(config);
const server = new WebpackDevServer(compiler, options)
server.listen(PORT, LOCALHOST, () => console.log(`server listening on port ${PORT}`));
}
startServer({
contentBase: path.join(__dirname, 'dist'),
historyApiFallback: true,
inline: true,
compress: true,
hot: true,
})