【taro react】---- Automatically delete console and debugger when packaging

1. Delete console and debugger implementations when compiling

  1. Override the console.log method globally to judge the compilation environment. Only in the development environment, console.log will be executed, otherwise it will not be executed. The disadvantage cannot be solved by deleting the debugger. At the same time, the console in the code is not deleted, but it is not executed, and it is not recommended to use it.
  2. Taro uses Webpack for packaging, so you can use Webpack plug-ins to delete console and debugger.

2. Use the Webpack plugin to delete

  1. Select the plug-in: front-end notes----TerserWebpackPlugin configuration ;
  2. Configuration plugin: custom Webpack configuration ; example:
// 这是一个添加插件的例子
module.exports = {
  // ...
  mini: {
    // ...
    webpackChain(chain, webpack) {
      chain.merge({
        plugin: {
          install: {
            plugin: require('npm-install-webpack-plugin'),
            args: [
              {
                // Use --save or --save-dev
                dev: false,
    

Guess you like

Origin blog.csdn.net/m0_38082783/article/details/130741050