Skip to content

Commit c1ba176

Browse files
committed
feat: add possibility to extend default minimize options
1 parent 576b781 commit c1ba176

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ module.exports = {
534534

535535
See [html-minifier-terser](https://github.com/DanielRuf/html-minifier-terser)'s documentation for more information on the available options.
536536

537-
The rules can be disabled using the following options in your `webpack.conf.js`
537+
The default rules can be overridden using the following options in your `webpack.conf.js`
538538

539539
**webpack.config.js**
540540

@@ -556,7 +556,31 @@ module.exports = {
556556
},
557557
};
558558
```
559+
The default rules can be extended:
559560

561+
**webpack.config.js**
562+
563+
```js
564+
const defaultMinimizerOptions = require('html-loader/dist/utils').defaultMinimizerOptions;
565+
566+
module.exports = {
567+
module: {
568+
rules: [
569+
{
570+
test: /\.html$/i,
571+
loader: "html-loader",
572+
options: {
573+
minimize: {
574+
...defaultMinimizerOptions,
575+
removeComments: false,
576+
collapseWhitespace: false,
577+
},
578+
},
579+
},
580+
],
581+
},
582+
};
583+
```
560584
### `esModule`
561585

562586
Type: `Boolean`

src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ function isProductionMode(loaderContext) {
496496
return loaderContext.mode === "production" || !loaderContext.mode;
497497
}
498498

499-
const defaultMinimizerOptions = {
499+
export const defaultMinimizerOptions = {
500500
caseSensitive: true,
501501
// `collapseBooleanAttributes` is not always safe, since this can break CSS attribute selectors and not safe for XHTML
502502
collapseWhitespace: true,

0 commit comments

Comments
 (0)