Reputation: 9604
Is it possible have webpack output multiple ECMAScript versions?
Something like:
EDIT:
What I mean, is wether Webpack can create both variants in one single run.
Upvotes: 2
Views: 1971
Reputation: 106
In one pass, I'm not sure you can do it with webpack. But you can export multiple targets using an array of configurations.
If you use babel 7, you can do something like this (untested):
module.exports = [
{
output: {
filename: './dist-bundle-es5.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [
[
'@babel/preset-env',
{
forceAllTransforms: true
}
]
]
}
}
}
]
},
name: 'es5',
entry: './app.js'
},
{
output: {
filename: './dist-bundle-es6.js'
},
name: 'es6',
entry: './app.js'
}
];
Check: https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations
Edit: add example
Upvotes: 4