Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to extend default minimize options #414

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
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
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
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
Expand Up @@ -496,7 +496,7 @@ function isProductionMode(loaderContext) {
return loaderContext.mode === "production" || !loaderContext.mode;
}

const defaultMinimizerOptions = {
export const defaultMinimizerOptions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reexport it in index.js, we should avoid using html-loader/dist/utils, because structure can be changed, better to use require('html-loader').defaultMinimizerOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reexported + fixed docs

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