-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathDiscardFilePlugin.mjs
32 lines (30 loc) · 1.47 KB
/
DiscardFilePlugin.mjs
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
import webpack from "webpack";
// eslint-disable-next-line no-restricted-imports -- TODO: Rule should not apply here
import isolatedComponentList from "../src/components/isolatedComponentList.mjs";
// https://github.com/pixiebrix/pixiebrix-extension/pull/7363#discussion_r1458224740
export default class DiscardFilePlugin {
apply(compiler) {
compiler.hooks.compilation.tap("DiscardFilePlugin", (compilation) => {
compilation.hooks.processAssets.tapPromise(
{
name: "DiscardFilePlugin",
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
},
async (assets) => {
// These files are not used, they're only webpack entry points in order to generate
// a full CSS files that can be injected in shadow DOM. See this for more context:
// https://github.com/webpack-contrib/mini-css-extract-plugin/issues/1092#issuecomment-2037540032
for (const componentPath of isolatedComponentList) {
delete assets[`${componentPath.split("/").pop()}.js`];
// If `delete assets[]` causes issues in the future, try replacing the content instead:
// assets["DocumentView.js"] = new webpack.sources.RawSource('"Dropped"');
}
// TODO: Remove these 3 from here and use <IsolatedComponent/>
delete assets["DocumentView.js"];
delete assets["EphemeralFormContent.js"];
delete assets["CustomFormComponent.js"];
},
);
});
}
}