-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig-overrides.js
81 lines (75 loc) · 2.72 KB
/
config-overrides.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
const util = require("util");
module.exports = function override(config, env) {
// prevent chunking for all files
Object.assign(config.optimization, {
runtimeChunk: false,
splitChunks: {
cacheGroups: {
default: false
}
}
});
// prevent hashes for the JS files
Object.assign(config.output, { filename: "static/js/[name].js" });
// prevent hashes for the CSS files
// search for the "MiniCssExtractPlugin" so we can remove the hashing in the filename
for (const plugin of config.plugins) {
if (!plugin || !plugin.constructor) {
// do nothing if the plugin is null
continue;
}
if (plugin.constructor.name === "MiniCssExtractPlugin") {
Object.assign(plugin.options, {
filename: "static/css/[name].css"
});
delete plugin.options.chunkFilename;
}
}
// minimize only the .min.js files
for (const plugin of config.optimization.minimizer) {
if (!plugin || !plugin.constructor) {
// do nothing if the plugin is null
continue;
}
/*
if (plugin.constructor.name === "TerserPlugin") {
Object.assign(plugin.options, { include: /\.min\.js$/ });
}
*/
if (plugin.constructor.name === "OptimizeCssAssetsWebpackPlugin") {
Object.assign(plugin.options, { assetNameRegExp: /\.min\.css$/ });
}
}
/*
// disable hot module reloading because Greasemonkey cannot handle it
// Delete any entries to the "HotDev" client
config.entry = config.entry.filter(
x => !x.toLowerCase().includes("hotdev")
);
config.plugins = config.plugins.filter(
x => !x || x.constructor.name !== "HotModuleReplacementPlugin"
);
// Even in production mode, we want the CSS inlined instead of put in a different file
// Remove the CSS extract plugin because we want CSS injected directly in
// the greasemonkey script
config.plugins = config.plugins.filter(
x => !x || x.constructor.name !== "MiniCssExtractPlugin"
);
(config.module.rules.find(x => !!x.oneOf).oneOf || []).forEach(x => {
if (
x.test &&
x.test.constructor === RegExp &&
"test.css".match(x.test)
) {
try {
x.use = x.use.filter(y => !y.loader.includes("css-extract"));
x.use.unshift(require.resolve("style-loader"));
} catch (e) {
// If we fail to replace a `css-extract` move on silently
// This will happen if, for example, it has already been replaced
}
}
});
*/
return config;
};