1

你能帮我在 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
                    },
                },
            },
        ],
    },
});
4

1 回答 1

0

只需安装 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-03-06T22:53:36.147 回答