7

I have read the part of the Webpack documentation that explains why Webpack will minify HTML when setting a loader using the module.loaders syntax. But I can't find anywhere that explains how to stop this. I am using pug-loader and html-webpack-plugin to process my templates, but Webpack always spits them out with the HTML minified.

How can I stop this?

{ test: /\.pug$/, use: 'pug-loader' } new HtmlWebpackPlugin({ title: 'Home', filename: 'index.html', template: './src/index.pug', inject: 'head', chunks: ['app'], hash: true }), 

4 Answers 4

9

There's an option for html-webpack-plugin. minify: false. Have you tried adding that?

https://github.com/jantimon/html-webpack-plugin#configuration

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried that, the files in the dist folder are still minified though.
(A bit late to the party, but...) mode: production seems to override minify: false, setting it to mode: none helps.
7
+50

This issue may help you.

loaders: [ { test: /\.pug$/, exclude: /(node_modules)/, loader: "pug-html", query: { pretty: true } } ] 

2 Comments

That is using the pug-html-loader plug in.
Although, that option is also available for pug-loader and works, so thanks!
3

Below command works for both npm run dev and npm run prod

 module: { rules: [{ test: /\.pug$/, use: [ 'html-loader?minimize=false', 'pug-html-loader?pretty=true' ] }] }, 

Comments

0

This works for me:

rules: [{ test: /\.pug$/, use: [ { loader: 'html-loader', options: { minimize: false } }, { loader: 'pug-html-loader', options: { pretty: true } } ], }], 

1 Comment

Does this work even with optimization: { minimizer ... } in production too?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.