-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.plugins.js
46 lines (40 loc) · 1.28 KB
/
webpack.plugins.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
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
class AssetRelocatorForgePatch {
apply(compiler) {
const isProd = compiler.options.mode === "production";
compiler.hooks.compilation.tap(
"asset-relocator-forge-patch",
(compilation) => {
compilation.mainTemplate.hooks.requireExtensions.intercept({
register: (tapInfo) => {
if (tapInfo.name == "asset-relocator-loader") {
const origFn = tapInfo.fn;
tapInfo.fn = (source, chunk) => {
const origOutput = origFn(source, chunk);
if (isProd) {
return (
"const { dirname, resolve } = require('path');\n" +
origOutput.replace(
"__dirname",
"resolve(dirname(__filename), '..')"
)
);
} else {
return origOutput.replace(
"__dirname",
JSON.stringify(compiler.options.output.path)
);
}
};
}
return tapInfo;
},
});
}
);
}
}
module.exports = [
new ForkTsCheckerWebpackPlugin(),
new AssetRelocatorForgePatch(),
];