-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev-server.js
45 lines (39 loc) · 1.11 KB
/
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
36
37
38
39
40
41
42
43
44
45
const
fs = require('fs'),
path = require('path'),
https = require('https'),
express = require('express'),
webpack = require('webpack'),
history = require('connect-history-api-fallback')
const app = express()
;(function() {
const webpackConfig = require(process.env.WEBPACK_CONFIG || './webpack.config')
app.use(history({
rewrites: [{
from: /^\/widget\/?$/,
to: '/widget/index.html'
}]
}))
webpackConfig.forEach((config, index) => {
const compiler = webpack(config)
app
.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
index: 'index.html'
}))
.use(require('webpack-hot-middleware')(compiler, {
log: console.log,
path: `${config.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())
)
}