为了账号安全,请及时绑定邮箱和手机立即绑定

webpack4如何删除sass或css内的注释?

请教,如何删除sass或css内的注释哪?

正在回答

2 回答

const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

    optimization: {
        minimizer: [
            // 压缩CSS
            new OptimizeCSSAssertsPlugin({}),
            // 压缩JS
            new UglifyJsPlugin({
                // 有很多可以配置
                cache: true,
                parallel: true,
                sourceMap: true,
                uglifyOptions: {
                     // 在UglifyJs删除没有用到的代码时不输出警告
                    warnings: false,
                    output: {
                        // 删除所有的注释
                        comments: false,
                        // 最紧凑的输出
                        beautify: false
                    },
                    compress: {
                        // 删除所有的 `console` 语句
                        // 还可以兼容ie浏览器
                        drop_console: true,
                        // 内嵌定义了但是只用到一次的变量
                        collapse_vars: true,
                        // 提取出出现多次但是没有定义成变量去引用的静态值
                        reduce_vars: true,
                    }
                }
            })
        ]
    },


0 回复 有任何疑惑可以回复我~
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

    optimization: {
        minimizer: [
            // 压缩CSS
            new OptimizeCSSAssertsPlugin({}),
            // 压缩JS
            new UglifyJsPlugin({
                // 有很多可以配置
                cache: true,
                parallel: true,
                sourceMap: true,
                uglifyOptions: {
                     // 在UglifyJs删除没有用到的代码时不输出警告
                    warnings: false,
                    output: {
                        // 删除所有的注释
                        comments: false,
                        // 最紧凑的输出
                        beautify: false
                    },
                    compress: {
                        // 删除所有的 `console` 语句
                        // 还可以兼容ie浏览器
                        drop_console: true,
                        // 内嵌定义了但是只用到一次的变量
                        collapse_vars: true,
                        // 提取出出现多次但是没有定义成变量去引用的静态值
                        reduce_vars: true,
                    }
                }
            })
        ]
    },


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
webpack深入与实战
  • 参与学习       86561    人
  • 解答问题       721    个

webpack实战教程,用真实项目带你探索 webpack 强大的功能

进入课程

webpack4如何删除sass或css内的注释?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信