import{_ as s,o as n,c as a,R as l}from"./chunks/framework.6241eaf2.js";const i=JSON.parse('{"title":"去掉 console.log","description":"","frontmatter":{},"headers":[],"relativePath":"guide/vue2/console.md","filePath":"guide/vue2/console.md","lastUpdated":1687776555000}'),o={name:"guide/vue2/console.md"},p=l(`

去掉 console.log

保留了测试环境和本地环境的 console.log

bash
npm i -D babel-plugin-transform-remove-console

在 babel.config.js 中配置

javascript
// 获取 VUE_APP_ENV 非 NODE_ENV,测试环境依然 console
const IS_PROD = ["production", "prod"].includes(process.env.VUE_APP_ENV);
const plugins = [
  [
    "import",
    {
      libraryName: "vant",
      libraryDirectory: "es",
      style: true,
    },
    "vant",
  ],
];
// 去除 console.log
if (IS_PROD) {
  plugins.push("transform-remove-console");
}

module.exports = {
  presets: [["@vue/cli-plugin-babel/preset", { useBuiltIns: "entry" }]],
  plugins,
};
`,5),e=[p];function t(c,r,D,y,F,C){return n(),a("div",null,e)}const u=s(o,[["render",t]]);export{i as __pageData,u as default};