I'm having trouble getting Webpack 5 to output es5 compatible code while also using the "dependOn" entry parameter.
I'm using Babel to transpile my code, which works fine, but unless I set the webpack target as "es5", webpack itself outputs incompatible code.
I'm using the entry parameter "dependOn", which behaves as expected with target: "web", but as soon as I change that to "es5" I get "Error in main.build.js from Terser" and "Unexpected token: punc(:) [main.build.js:3,9]".
Removing the "dependOn" parameter allows it to compile, but then I get my vendor libraries added to each entry.
Here is a minimal webpack config that reproduces the issue (commenting out either target: "es5" or dependOn: "vendor" fixes it):
const path = require('path');
module.exports = {
mode: "production",
target: "es5",
entry: {
vendor: "./src/test.js",
main: {
dependOn: "vendor",
import: ['./src/main.js']
}
},
output: {
filename: '[name].build.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
}
};
"test.js" and "main.js" can contain anything, the build still fails if they just have a "console.log" statement in each.
My package devDependencies contains the following: "@babel/core": "^7.14.3", "@babel/preset-env": "^7.14.2", "babel-loader": "^8.2.2", "webpack": "^5.37.1", "webpack-cli": "^4.7.0".
And my .babelrc contains {"presets": ["@babel/preset-env"]}