I have the following webpack config:
const path = require('path');
const webpack = require('webpack');
function NoOpPlugin(options) {
// Setup the plugin instance with options...
}
NoOpPlugin.prototype.apply = function(compiler) {
compiler.plugin('done', function(){});
};
module.exports = {
entry: {
main: __dirname + '/src/public/mainapp/app.js'
},
output: {
path: __dirname + "/assets/dist",
filename: '[name].min.js',
},
externals: {
window: 'window'
},
module: {
loaders: [
{
test: /\.modernizrrc.js$/,
loader: "modernizr"
},
{
test: /\.modernizrrc(\.json)?$/,
loader: "modernizr!json"
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
"presets": [
["env", {
"targets": {
"browsers": [
"> 1%",
"last 2 versions"
]
},
"useBuiltIns": true
}]
],
"plugins": [
"inferno",
"transform-decorators-legacy",
"transform-object-rest-spread"
]
}
},
{
test: /\.js$/,
loader: "eslint-loader",
exclude: /node_modules/
}
]
},
resolve: {
alias: {
modernizr$: path.resolve(__dirname, ".modernizrrc")
}
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
BROWSER: JSON.stringify(true),
NODE_ENV: JSON.stringify(process.env.NODE_ENV || '')
}
}),
process.env.NODE_ENV === 'production' ? new webpack.optimize.UglifyJsPlugin() : new NoOpPlugin()
]
}
If I place import 'babel-polyfill';
at the beginning of my app.js file babel-preset-env will transform it to only use the polyfills I need.
I'd like webpack to insert the polyfills without having to modify my source though. I know I can change my entrypoint to ['babel-polyfill', __dirname + '/src/public/mainapp/app.js'], but then every polyfill gets added to the output whether I need it or not. Any way to do this while still selecting just the polyfills I need?