| 14 | } |
| 15 | |
| 16 | apply(compiler: Compiler) { |
| 17 | const { entry } = compiler.options; |
| 18 | |
| 19 | entry[this.entryName].import = [this.loaderPath, ...entry[this.entryName].import]; |
| 20 | |
| 21 | compiler.hooks.compilation.tap('SheetPlugin', (compilation: Compilation) => { |
| 22 | if (!compilation.compiler.parentCompilation) { |
| 23 | compilation.hooks.processAssets.tap( |
| 24 | { |
| 25 | name: 'SheetPlugin', |
| 26 | stage: Compilation.PROCESS_ASSETS_STAGE_REPORT, |
| 27 | }, |
| 28 | () => { |
| 29 | const cssExists = !!compilation.getAsset(this.cssName); |
| 30 | |
| 31 | if (!cssExists) { |
| 32 | // locate target asset |
| 33 | const targetName = `${this.entryName}.js`; |
| 34 | const asset = compilation.getAsset(targetName); |
| 35 | |
| 36 | if (asset) { |
| 37 | const source = asset.source.source().toString(); |
| 38 | const updated = source.replace('window.__NO_CSS__', 'true'); |
| 39 | compilation.updateAsset(targetName, new RawSource(updated)); |
| 40 | } |
| 41 | } |
| 42 | }, |
| 43 | ); |
| 44 | } |
| 45 | }); |
| 46 | } |
| 47 | } |