我正试图阻止babel和webpack之间的最小化重命名我的功能。我遇到过this,但显然没有设置正确的选项。
这是我的webpack配置文件。我需要更改什么才能使其保留我的函数名称?
const path = require('path');
const MinifyPlugin = require('babel-minify-webpack-plugin');
module.exports = {
entry: {
translate: ["@babel/polyfill", "./Scripts/es6/translate.js"],
setupForm: ["./Scripts/es6/setupForm.js"],
prelimForm: ["./Scripts/es6/prelimForm.js"],
recruiters: ["./Scripts/es6/recruiters.js"]
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './Scripts/build'),
},
plugins: [
new MinifyPlugin({
"keepFnName": true
}, {})
],
module: {
rules: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/,
query: {
presets: ['@babel/preset-env']
}
}]
}
}
答案 0 :(得分:0)
缩小HTML的工作是terser-webpack-plugin,您可以将其传递给keep_fnames: false
。
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_fnames: false,
},
}),
],
},
};
答案 1 :(得分:0)
您可以要求Babel在您的babel.config / babelrc
中删除与此配置有关的旧浏览器兼容性:
presets: [
['@babel/preset-env', {targets: {browsers: ['> 2%']}}]
]
有关
targets
的更多信息:https://babeljs.io/docs/en/babel-preset-env#targets下降的浏览器兼容性:https://caniuse.com/#feat=mdn-javascript_builtins_function_name