-
-
Save PatrickJS/10f7b59bb444fc97ab85ca51600405b5 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
/* eslint-disable no-param-reassign */ | |
const path = require('path'); | |
const fse = require('fs-extra'); | |
class LoadablePlugin { | |
constructor({ filename = 'loadable-stats.json', writeToFileEmit = false } = {}) { | |
this.opts = { filename, writeToFileEmit }; | |
} | |
apply(compiler) { | |
// Add a custom output.jsonpFunction: __LOADABLE_LOADED_CHUNKS__ | |
compiler.options.output.jsonpFunction = '__LOADABLE_LOADED_CHUNKS__'; | |
compiler.hooks.emit.tap('@loadable/webpack-plugin', hookCompiler => { | |
const stats = hookCompiler.getStats().toJson({ | |
hash: true, | |
publicPath: true, | |
assets: true, | |
chunks: false, | |
modules: false, | |
source: false, | |
errorDetails: false, | |
timings: false | |
}); | |
const result = JSON.stringify(stats, null, 2); | |
hookCompiler.assets[this.opts.filename] = { | |
source() { | |
return result; | |
}, | |
size() { | |
return result.length; | |
} | |
}; | |
if (this.opts.writeToFileEmit) { | |
fse.outputFileSync(path.resolve(compiler.options.output.path, this.opts.filename), result); | |
} | |
}); | |
} | |
} | |
module.exports = LoadablePlugin; | |
module.exports.default = LoadablePlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment