-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.js
42 lines (33 loc) · 991 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
31
32
33
34
35
36
37
38
39
40
41
42
/* eslint no-console: 0 */
import express from 'express'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import fs from 'fs'
import config from './webpack.config.development'
const app = express()
const compiler = webpack(config)
const PORT = 3001
// compiler.apply(new DashboardPlugin({port: PORT}));
compiler.plugin('compile', () => {
console.log('Begin Webpack Build...')
})
compiler.plugin('done', (stats) => {
console.log('Build Complete.')
// https://webpack.github.io/analyse/
fs.writeFileSync('./stats.json', JSON.stringify(stats.toJson()))
console.log('Stats.json created')
})
app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true,
},
}))
app.use(webpackHotMiddleware(compiler))
app.listen(PORT, 'localhost', (err) => {
if (err) {
return
}
console.log(`Listening on http://localhost:${PORT}..`)
})