Vue项目发布过程中去除console

一、去除console

1.安装插件:babel-plugin-transform-remove-console
2.在项目中的babel.config.js中进行配置
	module.exports = {
	  presets: [
	    '@vue/cli-plugin-babel/preset'
	  ],
	  plugins: [
	    [
	      'component',
	      {
	        libraryName: 'element-ui',
	        styleLibraryName: 'theme-chalk'
	      }
	    ],
	    'transform-remove-console'    //新增配置项
	  ]
	}
3.重新运行build

二、只让上述配置在发布阶段生效,在开发阶段不生效

		// 项目发布阶段用到的babel插件
		const prodPlugins = []
		if (process.env.NODE_ENV === 'production') {
		  prodPlugins.push('transform-remove-console')
		}
		module.exports = {
		  presets: [
		    '@vue/cli-plugin-babel/preset'
		  ],
		  plugins: [
		    [
		      'component',
		      {
		        libraryName: 'element-ui',
		        styleLibraryName: 'theme-chalk'
		      }
		    ],
		    // 发布产品时的插件数组
		    ...prodPlugins
		  ]
		}

版权声明:本文为weixin_44871519原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。