1

Could you help me with the html minification code in one line after laravel-mix-pug?

My code is not working now and I don’t know what is the reason:

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
                    },
                },
            },
        ],
    },
});
Graham
  • 7,431
  • 18
  • 59
  • 84
SET
  • 55
  • 7

1 Answers1

0

Just install html-minifier and edit your package.json with laravel-mix scripts like that:

"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"

SET
  • 55
  • 7