首先安装 babel-plugin-transform-remove-console
npm i babel-plugin-transform-remove-console --save-dev
在babel.config.js文件中添加以下代码
// 然后在babel.config.js中添加判断
const prodPlugin = []
if (process.env.NODE_ENV === 'production') {
// 如果是生产环境,则自动清理掉打印的日志,但保留error 与 warn
prodPlugin.push([
'transform-remove-console',
{
// 保留 console.error 与 console.warn
exclude: ['error', 'warn']
}
])
}
//主要添加上边这段代码
module.exports = {
presets: [
// https://github.com/vuejs/vue-cli/tree/master/packages/@vue/babel-preset-app
'@vue/cli-plugin-babel/preset'
],
//和添加plugins这块
plugins: [
[
'import',
{
'libraryName': 'ant-design-vue',
'libraryDirectory': 'es',
'style': true
},
'ant-design-vue'
],
...prodPlugin
],
'env': {
'development': {
// babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require().
// This plugin can significantly increase the speed of hot updates, when you have a large number of pages.
'plugins': ['dynamic-import-node']
}
}
}
运行打包会报错如下图:
安装下就解决了
npm install antd babel-plugin-import --save
如果帮到您点赞收藏吧