问答详情
源自:4-4 处理项目中的 css

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

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

提问者:柱的 2019-04-16 16:13

个回答

  • 慕码人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,
                        }
                    }
                })
            ]
        },