-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize CSS assets added later by plugins (webpack@5 only) (#47)
- Loading branch information
1 parent
66c054f
commit bdb3f52
Showing
5 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export default class EmitNewAsset { | ||
constructor(options = {}) { | ||
this.options = options; | ||
} | ||
|
||
apply(compiler) { | ||
const pluginName = this.constructor.name; | ||
|
||
const { RawSource } = compiler.webpack.sources; | ||
|
||
compiler.hooks.compilation.tap(pluginName, (compilation) => { | ||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: pluginName, | ||
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT, | ||
}, | ||
() => { | ||
// eslint-disable-next-line no-param-reassign | ||
compilation.emitAsset( | ||
this.options.name, | ||
new RawSource(` | ||
.a { | ||
display: block; | ||
color: coral; | ||
} | ||
`) | ||
); | ||
} | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters