Vueがパッケージ化されると、ビルドによって左右のコンソールが削除されます

推奨プラグイン:babel-plugin-transform-remove-console

インストール:

 npm install babel-plugin-transform-remove-console --save-dev

 

.babelrc  (推奨)VUE-cli3.0 / babel.config.js定義プラグイン:[]


// without options   这个就可以
{
  "plugins": ["transform-remove-console"]
}

// with options
{
  "plugins": [ ["transform-remove-console", { "exclude": [ "error", "warn"] }] ]
}

 

module.exports = {
  'presets': [
    '@vue/app'
  ],
  'plugins': [
    [
      'component',
      {
        'libraryName': 'element-ui',
        'styleLibraryName': 'theme-chalk'
      }
    ],
    transform-remove-console
  ]
}

 

リリースフェーズでのみ有効にしたいが、開発フェーズでは有効にしたくない場合は、次のことを判断する必要があります。

// 项目开发阶段用到的babel插件
const prodPlugins = []
if (process.env.NODE_ENV === 'production') {
  prodPlugins.push('transform-remove-console')
}

module.exports = {
  'presets': [
    '@vue/app'
  ],
  'plugins': [
    [
      'component',
      {
        'libraryName': 'element-ui',
        'styleLibraryName': 'theme-chalk'
      }
    ],
    // 发布产品时候的插件数组
    ...prodPlugins
  ]
}

 

 

 

おすすめ

転載: blog.csdn.net/SmartJunTao/article/details/108705998