-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.dev.js
61 lines (45 loc) · 1.52 KB
/
app.dev.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
57
58
59
60
61
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const chokidar = require('chokidar');
const config = require('./webpack/development');
const { createServer } = require('./server');
const app = express();
const compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
quiet: true,
}));
app.use(webpackHotMiddleware(compiler));
const { server } = createServer(`${__dirname}/client`, { app });
server.keepAliveTimeout = 0;
app.use('*', (req, res, next) => {
const filename = `${compiler.outputPath}/index.html`;
compiler.outputFileSystem.readFile(filename, (err, result) => {
if (err) {
return next(err);
}
res.set('content-type', 'text/html');
res.send(result);
res.end();
});
});
const watcherServer = chokidar.watch('./server');
watcherServer.on('ready', () => {
watcherServer.on('all', () => {
console.log('Clearing /server/ module cache from server');
Object.keys(require.cache).forEach((id) => {
if (/[/\\]server[/\\]/.test(id)) delete require.cache[id];
});
});
});
const watcherShared = chokidar.watch('./shared');
watcherShared.on('ready', () => {
watcherShared.on('all', () => {
console.log('Clearing /shared/ module cache from shared');
Object.keys(require.cache).forEach((id) => {
if (/[/\\]shared[/\\]/.test(id)) delete require.cache[id];
});
});
});