-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdev-server.js
35 lines (30 loc) · 922 Bytes
/
dev-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
const
fs = require('fs'),
https = require('https'),
express = require('express'),
webpack = require('webpack')
const app = express()
;(function() {
const webpackConfig = require(process.env.WEBPACK_CONFIG || './webpack.config')
const compiler = webpack(webpackConfig)
app
.use(require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
// writeToDisk: true,
index: 'index.html'
}))
.use(require('webpack-hot-middleware')(compiler, {
log: console.log,
path: `${webpackConfig.output.publicPath}__webpack_hmr`,
heartbeat: 10 * 1000,
}))
})()
if (require.main === module) {
const server = https.createServer({
pfx: fs.readFileSync('./webpack/certificate/localhost.pfx'),
passphrase: 'localhost',
}, app)
server.listen(process.env.PORT || 8080, () =>
console.log('Listening on %j', server.address())
)
}