2018-01-20 00:06:59 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
module.exports = class RuntimeChunkPlugin {
|
|
|
|
constructor(options) {}
|
|
|
|
|
|
|
|
apply(compiler) {
|
2018-01-24 19:00:50 +08:00
|
|
|
compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
|
2018-01-20 00:06:59 +08:00
|
|
|
compilation.hooks.optimizeChunksAdvanced.tap("RuntimeChunkPlugin", () => {
|
|
|
|
for(const entrypoint of compilation.entrypoints.values()) {
|
|
|
|
const chunk = entrypoint.getRuntimeChunk();
|
|
|
|
if(chunk.getNumberOfModules() > 0) {
|
|
|
|
const newChunk = compilation.addChunk(entrypoint.name + "-runtime");
|
|
|
|
entrypoint.unshiftChunk(newChunk);
|
|
|
|
newChunk.addGroup(entrypoint);
|
|
|
|
entrypoint.setRuntimeChunk(newChunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|