-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
53 lines (45 loc) · 1.35 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require('fs');
const path = require('path');
const ManifestPlugin = require('webpack-manifest-plugin');
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const MANIFEST_PATH = path.resolve(__dirname, 'data', 'manifest.json');
module.exports = {
mode: IS_PRODUCTION ? 'production' : 'development',
devtool: IS_PRODUCTION ? false : 'cheap-module-eval-source-map',
entry: {
app: path.join(__dirname, 'src', 'js', 'app.js'),
},
output: {
filename: path.join('assets', '[name].[contenthash].js'),
path: path.resolve(__dirname, 'static'),
publicPath: '/',
},
plugins: [
new ManifestPlugin({
fileName: MANIFEST_PATH,
generate: (seed, files) => {
let current = {};
try {
current = JSON.parse(
fs.readFileSync(MANIFEST_PATH, { encoding: 'utf8' }),
);
current = Object.keys(current)
.filter(key => !key.startsWith('precache-manifest.'))
.reduce(
(acc, cur) => ({
...acc,
[cur]: `/${current[cur].replace(/^\//, '')}`,
}),
{},
);
} catch (e) {
console.error(e);
}
return files.reduce(
(acc, { name, path: p }) => ({ ...acc, [name]: p }),
{ ...seed, ...current },
);
},
}),
],
};