使用由 Vue CLI 4 创建的 VueJS 项目,您可以在 babel.config.js
中使用这个方便的预设配置 Babel :
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
],
};
我正在尝试使用 babel-plugin-transform-remove-console删除
console.*
从构建的 JS 文件中。通过
npm i -D babel-plugin-transform-remove-console
将插件安装为开发依赖项然后修改
babel.config.js
:module.exports = (api) => {
var env = api.cache(() => process.env.NODE_ENV);
var plugins = [];
// Change to 'production' when configs are working
if (env === 'development') {
plugins.push(['transform-remove-console', { exclude: ['error', 'warn'] }]);
}
return {
presets: ['@vue/cli-plugin-babel/preset'],
// plugins,
// Doesn't work even when always on?
plugins: ['transform-remove-console'],
};
};
这应该通过运行
npm run serve -- --reset-cache
来工作。 ,并且我也尝试过多次使用不同的环境构建应用程序,但控制台日志仍然显示在浏览器的控制台中?Vue CLI 的预设是否因无法通过此配置文件设置插件而以某种方式混淆?
更新:已创建 a bug report to Vue CLI repo ,并在创建最小的错误重现存储库时,我发现这个插件正在处理一个新项目 .
但是,我不知道是什么原因造成的,因为我已经将此应用程序与最新的 CLI 引导模板同步,并且还尝试通过 `npm cache clean --force 对 NPM 缓存进行 nuking。
最佳答案
我遇到了同样的问题。这不起作用:
plugins: ['transform-remove-console']
但这有效:plugins: [['transform-remove-console', { exclude: ['error', 'warn'] }]]
希望这可以帮助遇到同样问题的其他人。
关于javascript - Babel 插件 transform-remove-console 不适用于 Vue CLI 4 @vue/cli-plugin-babel/preset?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60204354/