-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize JS assets added later by plugins (#373)
- Loading branch information
1 parent
e10b8b4
commit fea6f20
Showing
5 changed files
with
72 additions
and
3 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,31 @@ | ||
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(` | ||
var foo = 'bar'; | ||
var bar = 'foo'; | ||
`) | ||
); | ||
} | ||
); | ||
}); | ||
} | ||
} |
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
Should this log be removed in next release?