-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontserver.local.js
56 lines (48 loc) · 1.47 KB
/
frontserver.local.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
46
47
48
49
50
51
52
53
54
55
56
const opn = require('opn')
const path = require('path')
const compression = require('compression')
const uuid = require('uuid')
const express = require('express')
const webpack = require('webpack')
const webpackMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const MemoryFileSystem = require('memory-fs')
require('dotenv').config({ path: './config/local.env' })
const config = require('./webpack.config.js')
const port = process.env.PORT
const app = express()
app.disable("x-powered-by")
const compiler = webpack(config)
const middleware = webpackMiddleware(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false,
},
outputFileSystem: new MemoryFileSystem() // Set the outputFileSystem option
})
app.use(middleware)
app.use('/static', express.static(path.join(__dirname, 'static')))
app.use(webpackHotMiddleware(compiler))
app.get('*', (req, res) => {
console.log(compiler.outputPath, `compiler.outputPath`)
var filename = path.join(compiler.outputPath, 'index.html');
compiler.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, '0.0.0.0', function onStart(err) {
if (err) {
console.log(err)
}
opn(`http://localhost:${port}`);
})