forked from ruanyl/reapex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (26 loc) · 878 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
const webpack = require('webpack')
const path = require('path')
const webpackDevMiddleware = require('webpack-dev-middleware')
const config = require('./webpack.config')
const app = new (require('express'))()
const port = 3030
const compiler = webpack(config)
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config[1].output.publicPath }))
app.use((req, res, next) => {
const filename = path.join(compiler.compilers[1].outputPath, 'index.html')
compiler.compilers[1].outputFileSystem.readFile(filename, function(err, result) {
if (err) {
return next(err)
}
res.set('content-type', 'text/html')
res.send(result)
res.end()
})
})
app.listen(port, error => {
if (error) {
console.error(error)
} else {
console.info('==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port)
}
})