-
Notifications
You must be signed in to change notification settings - Fork 34
/
webpack.config.js
32 lines (30 loc) · 1.01 KB
/
webpack.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
const envsubst = require('@tuplo/envsubst');
const path = require('path');
module.exports = {
optimization: {
splitChunks: {
cacheGroups: {
config: {
name: 'config',
filename: 'config.js',
chunks: 'all',
test: (module) => module.resource?.includes('/src/config.ts'),
enforce: true,
},
},
},
},
devServer: {
setupMiddlewares: (middlewares, devServer) => {
devServer.app.get('/config.js', (req, res) => {
const { outputPath, outputFileSystem: fs } = devServer.compiler;
const rawFile = fs.readFileSync(path.resolve(outputPath, 'config.js'), {
encoding: 'utf8',
});
const substituted = envsubst(rawFile);
res.type('application/javascript').send(substituted);
});
return middlewares;
},
},
};