【问题标题】:Minify HTML after Pug compilation with Laravel Mix使用 Laravel Mix 压缩 Pug 编译后的 HTML
【发布时间】:2020-03-03 14:49:46
【问题描述】:

你能帮我在 laravel-mix-pug 之后的一行中的 html 缩小代码吗?

我的代码现在不起作用,我不知道是什么原因:

let mix = require('laravel-mix');
mix.pug = require('laravel-mix-pug');

let pretty = true;
if (mix.inProduction()) pretty = false;

mix.js(['src/js/main.js', 'src/js/plugins.js'], 'dist/js/scripts.js')
    .sass('src/sass/app.scss', 'dist/css/styles.css')
    .options({
        processCssUrls: false
    })
    .pug('src/*.pug', '../dist', {
        pug: {
            pretty: pretty
        }
    });

mix.webpackConfig({
    module: {
        rules: [
            {
                test: /\.html$/,
                loader: 'html-loader',
                options: {
                    minimize: {
                        removeComments: true,
                        collapseWhitespace: true,
                        minifyJS: true
                    },
                },
            },
        ],
    },
});

【问题讨论】:

    标签: html minify laravel-mix pug-loader


    【解决方案1】:

    只需安装 html-minifier 并使用 laravel-mix 脚本编辑你的 package.json:

    "minify": "html-minifier --input-dir ./dist --output-dir ./dist --file-ext html --collapse-whitespace --remove-comments --process-conditional-comments --minify-js true", "prod": "npm run production && npm run minify"

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 2019-07-01
      • 2020-08-04
      • 2022-01-03
      • 2018-06-19
      • 2021-05-11
      相关资源
      最近更新 更多