Created
October 14, 2017 23:53
-
-
Save k-maru/189d7df19b9df9cf2e219de56b9db1c0 to your computer and use it in GitHub Desktop.
WebPack で core-js のカスタムビルド結果をくっつける
This file contains hidden or 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
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