Last active
November 24, 2019 09:15
-
-
Save wwayne/bba7398010650b110be217510a88f4d0 to your computer and use it in GitHub Desktop.
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
'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