Skip to content

Commit 0fa36af

Browse files
authored
feat: add possibility to extend default minimize options (#414)
1 parent 3ff3077 commit 0fa36af

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

README.md

+27-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

@@ -557,6 +557,32 @@ module.exports = {
557557
};
558558
```
559559

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

562588
Type: `Boolean`

src/cjs.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ const loader = require("./index");
22

33
module.exports = loader.default;
44
module.exports.raw = loader.raw;
5+
module.exports.defaultMinimizerOptions = loader.defaultMinimizerOptions;

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getImportCode,
66
getModuleCode,
77
getExportCode,
8+
defaultMinimizerOptions,
89
} from "./utils";
910

1011
import schema from "./options.json";
@@ -52,3 +53,5 @@ export default async function loader(content) {
5253

5354
return `${importCode}${moduleCode}${exportCode}`;
5455
}
56+
57+
export { defaultMinimizerOptions };

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)