Skip to content

Instantly share code, notes, and snippets.

@wwayne
Last active November 24, 2019 09:15
Show Gist options
  • Save wwayne/bba7398010650b110be217510a88f4d0 to your computer and use it in GitHub Desktop.
Save wwayne/bba7398010650b110be217510a88f4d0 to your computer and use it in GitHub Desktop.
'use strict'
module.exports = class WebpackPugManifestPlugin {
apply (compiler) {
compiler.plugin('emit', function (compilation, cb) {
const JSAssets = Object.keys(compilation.assets).filter(asset => /\.js$/.test(asset))
JSAssets.sort((a, b) => {
if (/^manifest/.test(b)) return 1
if (/^vendor/.test(b) && !/^manifest/.test(a)) return 1
return 0
})
compilation.assets['sharedScript.pug'] = {
source: () => JSAssets.map(asset => `script(type="text/javascript", src="/public/shared/${asset}")`).join('\n'),
size: () => JSAssets.length
}
cb()
})
}
}
//test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment