Skip to content

Commit

Permalink
feat: add possibility to extend default minimize options (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
fretfan authored Jan 8, 2022
1 parent 3ff3077 commit 0fa36af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ module.exports = {

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

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

**webpack.config.js**

Expand All @@ -557,6 +557,32 @@ module.exports = {
};
```

The default rules can be extended:

**webpack.config.js**

```js
const { defaultMinimizerOptions } = require("html-loader");

module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-loader",
options: {
minimize: {
...defaultMinimizerOptions,
removeComments: false,
collapseWhitespace: false,
},
},
},
],
},
};
```

### `esModule`

Type: `Boolean`
Expand Down
1 change: 1 addition & 0 deletions src/cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ const loader = require("./index");

module.exports = loader.default;
module.exports.raw = loader.raw;
module.exports.defaultMinimizerOptions = loader.defaultMinimizerOptions;
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getImportCode,
getModuleCode,
getExportCode,
defaultMinimizerOptions,
} from "./utils";

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

return `${importCode}${moduleCode}${exportCode}`;
}

export { defaultMinimizerOptions };
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ function isProductionMode(loaderContext) {
return loaderContext.mode === "production" || !loaderContext.mode;
}

const defaultMinimizerOptions = {
export const defaultMinimizerOptions = {
caseSensitive: true,
// `collapseBooleanAttributes` is not always safe, since this can break CSS attribute selectors and not safe for XHTML
collapseWhitespace: true,
Expand Down

0 comments on commit 0fa36af

Please sign in to comment.