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

来源:4-4 处理项目中的 css

柱的

2019-04-16 16:13

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

写回答 关注

2回答

  • 慕码人7593232
    2019-12-01 21:31:20
    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,
                        }
                    }
                })
            ]
        },


  • 慕码人7593232
    2019-12-01 21:30:52
    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,
                        }
                    }
                })
            ]
        },


webpack深入与实战

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

86561 学习 · 721 问题

查看课程

相似问题