-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathwebpack.dev.config.js
92 lines (86 loc) · 2.4 KB
/
webpack.dev.config.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const path = require('path');
const setupLocalProxyRewrite = require('../src/applications/proxy-rewrite/local-proxy-rewrite');
const manifestHelpers = require('./manifest-helpers');
function generateWebpackDevConfig(buildOptions) {
const routes = manifestHelpers.getAppRoutes();
const appRewrites = routes
.map(url => ({
from: `^${url}(.*)`,
to: `${url}/`,
}))
.sort((a, b) => b.from.length - a.from.length);
const webSocketURL = {};
try {
const publicUrl = new URL(buildOptions.public);
webSocketURL.hostname = publicUrl.hostname;
webSocketURL.port = publicUrl.port || undefined;
if (!webSocketURL.port) {
webSocketURL.port = publicUrl.protocol === 'https:' ? 443 : 80;
}
webSocketURL.protocol = publicUrl.protocol === 'https:' ? 'wss:' : 'ws:';
} catch {
webSocketURL.hostname = buildOptions.public || undefined;
}
// If in watch mode, use webpack devserver.
return {
historyApiFallback: {
rewrites: [
...appRewrites,
{
from: '^/(.*)',
to(context) {
return context.parsedUrl.pathname;
},
},
],
},
hot: false,
liveReload: false,
static: {
directory: path.resolve(
__dirname,
'../',
'build',
buildOptions.destination,
),
watch: {
poll: 1000,
},
},
port: buildOptions.port,
host: buildOptions.host,
client: { webSocketURL },
devMiddleware: {
publicPath: '/generated/',
stats: {
colors: true,
assets: false,
version: false,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
entrypoints: false,
children: false,
modules: false,
warnings: true,
},
// Needed to write the landing pages to disk so webpack-dev-server will actually serve them
writeToDisk: true,
},
setupMiddlewares: (middlewares, devServer) => {
// We're doing this because some of the pages
// that we are redirecting end with asp and we want
// those to be treated as html
devServer.app.get(/.*\.asp/, (req, res, next) => {
res.type('html');
next();
});
if (buildOptions['local-proxy-rewrite']) {
setupLocalProxyRewrite(devServer, buildOptions);
}
return middlewares;
},
};
}
module.exports = generateWebpackDevConfig;