From 7e14f72a046cc7598dcf9c20cfd2e5eac5327d05 Mon Sep 17 00:00:00 2001 From: Sergei Kossik Date: Wed, 5 Jan 2022 21:03:41 +0200 Subject: [PATCH] feat: add possibility to extend default minimize options --- README.md | 28 +++++++++++++++++++++++++++- src/cjs.js | 1 + src/index.js | 3 +++ src/utils.js | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09329e75..d443d62a 100644 --- a/README.md +++ b/README.md @@ -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** @@ -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` diff --git a/src/cjs.js b/src/cjs.js index 68eb6364..7acf6a7a 100644 --- a/src/cjs.js +++ b/src/cjs.js @@ -2,3 +2,4 @@ const loader = require("./index"); module.exports = loader.default; module.exports.raw = loader.raw; +module.exports.defaultMinimizerOptions = loader.defaultMinimizerOptions; diff --git a/src/index.js b/src/index.js index 819b5458..381dde17 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import { getImportCode, getModuleCode, getExportCode, + defaultMinimizerOptions, } from "./utils"; import schema from "./options.json"; @@ -52,3 +53,5 @@ export default async function loader(content) { return `${importCode}${moduleCode}${exportCode}`; } + +export { defaultMinimizerOptions }; diff --git a/src/utils.js b/src/utils.js index 4febb66e..ded72fed 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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,