webpack terser-webpack-plugin 不打包注释及log

踩坑记录:注意 terser-webpack-plugin": "^4.2.3" 对应着webpack4及版本一下的,5点多版本的对应webpack5,版本不对会报ERROR TypeError: Cannot read property 'javascript' of undefined

1.安装三方包
npm install terser-webpack-plugin

2.在vue.config.js中配置
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
  configureWebpack: {
    optimization: {
      minimize: true,//为了不影响dev时的构建速度
      minimizer: [
        new TerserPlugin({
          parallel: true,//使用多进程并发运行以提高构建速度 Boolean|Number 默认值: true  
          terserOptions: {
            compress: {
              drop_console: true,//移除所有console相关代码;
              drop_debugger: true,//移除自动断点功能;
              pure_funcs: ["console.log", "console.error"],//配置移除指定的指令,如console.log,alert等
            },
            format: {
              comments: false,//删除注释
            },
          },
          extractComments: false,//是否将注释剥离到单独的文件中
        })
      ]
    }
  }
}

相关推荐

  1. webpack terser-webpack-plugin 打包注释log

    2024-07-14 05:00:04       26 阅读
  2. webpack进阶 -- 自定义Plugin,Loader封装&打包优化

    2024-07-14 05:00:04       23 阅读
  3. Webpack打包

    2024-07-14 05:00:04       40 阅读
  4. Webpack打包

    2024-07-14 05:00:04       31 阅读
  5. Webpack的Loader和Plugin

    2024-07-14 05:00:04       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 05:00:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 05:00:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 05:00:04       58 阅读
  4. Python语言-面向对象

    2024-07-14 05:00:04       69 阅读

热门阅读

  1. Cesium中创建局部坐标系

    2024-07-14 05:00:04       27 阅读
  2. PostgreSQL的pg_dirtyread工具

    2024-07-14 05:00:04       23 阅读
  3. 怎样把pptx课件转换成word文档

    2024-07-14 05:00:04       26 阅读
  4. Github 2024-07-13 Rust开源项目日报 Top10

    2024-07-14 05:00:04       25 阅读
  5. 设计模式详解(十八)——责任链模式

    2024-07-14 05:00:04       21 阅读
  6. Vue3 关于scss预编译中:deep 其中的deep如何理解

    2024-07-14 05:00:04       22 阅读
  7. stm32使用通用定时器生成pwm

    2024-07-14 05:00:04       26 阅读
  8. 如何实现一个分布式锁

    2024-07-14 05:00:04       19 阅读
  9. BGP笔记的基本概要

    2024-07-14 05:00:04       23 阅读