Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生产环境移除 console.log #12

Open
cklwblove opened this issue Sep 22, 2019 · 0 comments
Open

生产环境移除 console.log #12

cklwblove opened this issue Sep 22, 2019 · 0 comments
Labels
feature new feature

Comments

@cklwblove
Copy link
Owner

  1. 使用 babel-plugin-transform-remove-console
  • 安装命令:yarn add babel-plugin-transform-remove-console --dev
  • 修改 babel.config.js
+ const plugins = [];

+ if (process.env.NODE_ENV === 'production') {
+  plugins.push('transform-remove-console');
+ }

module.exports = {
  presets: ['@vue/app'],
+  plugins,
};
  1. 使用 terser-webpack-plugin
    主要是 vue.config.js的修改
  • 引入插件
    const TerserPlugin = require('terser-webpack-plugin');
  • configureWebpack配置的修改
...
configureWebpack: () => ({
+ optimization: {
+      // https://webpack.docschina.org/configuration/optimization/#optimization-minimizer
+      minimizer: [
+        new TerserPlugin({
+          terserOptions: {
+            // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
+            compress: {
+              warnings: false,
+              drop_console: true,
+              drop_debugger: true,
+              pure_funcs: ['console.log'],
+            },
+          }
+        })
+      ],
+    },
+ })
...
@cklwblove cklwblove added the feature new feature label Sep 22, 2019
@cklwblove cklwblove changed the title feature:生产环境移除 console.log 生产环境移除 console.log Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature
Projects
None yet
Development

No branches or pull requests

1 participant