Skip to content

Instantly share code, notes, and snippets.

@k-maru
Created October 14, 2017 23:53
Show Gist options
  • Save k-maru/189d7df19b9df9cf2e219de56b9db1c0 to your computer and use it in GitHub Desktop.
Save k-maru/189d7df19b9df9cf2e219de56b9db1c0 to your computer and use it in GitHub Desktop.
WebPack で core-js のカスタムビルド結果をくっつける
const ConcatSource = require("webpack-sources").ConcatSource;
const corejsBuilder = require("core-js-builder");
function CoreJsBuildPlugin(options) {
this.options = options || { entry: {} };
}
CoreJsBuildPlugin.prototype.apply = function CoreJsBuildPlugin(compiler) {
const self = this;
compiler.plugin("compilation", function (compilation) {
compilation.plugin("optimize-chunk-assets", function (chunks, callback) {
corejsBuilder(self.options).then(function (bundledCode) {
const code = bundledCode;
chunks.forEach(function (chunk) {
if (!chunk.isInitial) return;
chunk.files.forEach(function (file) {
// 先頭にくっつける
compilation.assets[file] = new ConcatSource("/* core-js */\n", code, compilation.assets[file]);
});
});
callback();
});
});
});
};
//....
module.exports = {
//....
plugins: [
new CoreJsBuildPlugin({ // https://github.com/zloirock/core-js#custom-build-from-external-scripts
modules: ["es6"],
blacklist: ["es6.reflect"],
library: false,
umd: true
})
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment