You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-40Lines changed: 47 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ or
36
36
pnpm add -D html-loader
37
37
```
38
38
39
-
Then add the plugin to your `webpack`config. For example:
39
+
Then add the loader to your `webpack`configuration. For example:
40
40
41
41
**file.js**
42
42
@@ -102,32 +102,33 @@ You may need to specify loaders for images in your configuration (recommended [`
102
102
103
103
Supported tags and attributes:
104
104
105
-
-the`src` attribute of the `audio` tag
106
-
-the`src` attribute of the `embed` tag
107
-
-the`src` attribute of the `img` tag
108
-
-the`srcset` attribute of the `img` tag
109
-
-the`src` attribute of the `input` tag
110
-
-the`data` attribute of the `object` tag
111
-
-the`src` attribute of the `script` tag
112
-
-the`href` attribute of the `script` tag
113
-
-the`xlink:href` attribute of the `script` tag
114
-
-the`src` attribute of the `source` tag
115
-
-the`srcset` attribute of the `source` tag
116
-
-the`src` attribute of the `track` tag
117
-
-the`poster` attribute of the `video` tag
118
-
-the`src` attribute of the `video` tag
119
-
-the`xlink:href` attribute of the `image` tag
120
-
-the`href` attribute of the `image` tag
121
-
-the`xlink:href` attribute of the `use` tag
122
-
-the`href` attribute of the `use` tag
123
-
-the`href` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`, `manifest`, `prefetch`, `preload` or when the `itemprop` attribute is `image`, `logo`, `screenshot`, `thumbnailurl`, `contenturl`, `downloadurl`, `duringmedia`, `embedurl`, `installurl`, `layoutimage`
124
-
-the`imagesrcset` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`, `manifest`, `prefetch`, `preload`
125
-
-the`content` attribute of the `meta` tag when the `name` attribute is `msapplication-tileimage`, `msapplication-square70x70logo`, `msapplication-square150x150logo`, `msapplication-wide310x150logo`, `msapplication-square310x310logo`, `msapplication-config`, `twitter:image` or when the `property` attribute is `og:image`, `og:image:url`, `og:image:secure_url`, `og:audio`, `og:audio:secure_url`, `og:video`, `og:video:secure_url`, `vk:image` or when the `itemprop` attribute is `image`, `logo`, `screenshot`, `thumbnailurl`, `contenturl`, `downloadurl`, `duringmedia`, `embedurl`, `installurl`, `layoutimage`
126
-
-the`icon-uri` value component in `content` attribute of the `meta` tag when the `name` attribute is `msapplication-task`
105
+
-The`src` attribute of the `audio` tag
106
+
-The`src` attribute of the `embed` tag
107
+
-The`src` attribute of the `img` tag
108
+
-The`srcset` attribute of the `img` tag
109
+
-The`src` attribute of the `input` tag
110
+
-The`data` attribute of the `object` tag
111
+
-The`src` attribute of the `script` tag
112
+
-The`href` attribute of the `script` tag
113
+
-The`xlink:href` attribute of the `script` tag
114
+
-The`src` attribute of the `source` tag
115
+
-The`srcset` attribute of the `source` tag
116
+
-The`src` attribute of the `track` tag
117
+
-The`poster` attribute of the `video` tag
118
+
-The`src` attribute of the `video` tag
119
+
-The`xlink:href` attribute of the `image` tag
120
+
-The`href` attribute of the `image` tag
121
+
-The`xlink:href` attribute of the `use` tag
122
+
-The`href` attribute of the `use` tag
123
+
-The`href` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`, `manifest`, `prefetch`, `preload` or when the `itemprop` attribute is `image`, `logo`, `screenshot`, `thumbnailurl`, `contenturl`, `downloadurl`, `duringmedia`, `embedurl`, `installurl`, `layoutimage`
124
+
-The`imagesrcset` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`, `manifest`, `prefetch`, `preload`
125
+
-The`content` attribute of the `meta` tag when the `name` attribute is `msapplication-tileimage`, `msapplication-square70x70logo`, `msapplication-square150x150logo`, `msapplication-wide310x150logo`, `msapplication-square310x310logo`, `msapplication-config`, `twitter:image` or when the `property` attribute is `og:image`, `og:image:url`, `og:image:secure_url`, `og:audio`, `og:audio:secure_url`, `og:video`, `og:video:secure_url`, `vk:image` or when the `itemprop` attribute is `image`, `logo`, `screenshot`, `thumbnailurl`, `contenturl`, `downloadurl`, `duringmedia`, `embedurl`, `installurl`, `layoutimage`
126
+
-The`icon-uri` value component in `content` attribute of the `meta` tag when the `name` attribute is `msapplication-task`
127
127
128
128
#### `boolean`
129
129
130
-
The `true` value enables the processing of all default elements and attributes, the `false` value disables the processing of all attributes.
130
+
- true: Enables processing of all default tags and attributes
131
+
- false: Disables processing entirely
131
132
132
133
**webpack.config.js**
133
134
@@ -150,7 +151,7 @@ module.exports = {
150
151
151
152
#### `object`
152
153
153
-
Allows you to specify which tags and attributes to process, filter them, filter urls and process sources starting with `/`.
154
+
Allows you to specify which tags and attributes to process, filter them, filter URLs and process sources starting with `/`.
154
155
155
156
For example:
156
157
@@ -291,7 +292,7 @@ module.exports = {
291
292
292
293
If the tag name is not specified it will process all the tags.
293
294
294
-
> You can use your custom filter to specify html elements to be processed.
295
+
> You can use your custom filter to specify HTML elements to be processed.
295
296
296
297
For example:
297
298
@@ -418,7 +419,7 @@ type urlFilter = (
418
419
419
420
Default: `undefined`
420
421
421
-
Allow to filter urls. All filtered urls will not be resolved (left in the code as they were written).
422
+
Allow to filter URLs. All filtered URLs will not be resolved (left in the code as they were written).
422
423
Non-requestable sources (for example `<img src="javascript:void(0)">`) are not handled by default.
423
424
424
425
```js
@@ -459,9 +460,9 @@ type scriptingEnabled = boolean;
459
460
460
461
Default: `true`
461
462
462
-
By default, the parser in `html-loader` interprets content inside `<noscript>` tags as `#text`, so processing of content inside this tag will be ignored.
463
+
By default, the parser in `html-loader` interprets content inside `<noscript>` tags as plain `#text`, so processing of content inside these tags will is ignored during processing.
463
464
464
-
In order to enable processing inside `<noscript>` for content recognition by the parser as `#AST`, set this parameter to: `false`
465
+
In order to enable processing inside `<noscript>` for content recognition by the parser as `#AST`, set this option to: `false`
Allows pre-processing of content before handling by the loader.
500
501
501
502
> [!WARNING]
502
503
>
503
-
> You should always return valid HTML
504
+
> You should always return valid HTML.
504
505
505
506
**file.hbs**
506
507
@@ -642,7 +643,7 @@ module.exports = {
642
643
};
643
644
```
644
645
645
-
You can also set the `postprocessor` option as an asynchronous function instance.
646
+
You can also set the `postprocessor` option as an asynchronous `function` instance.
646
647
647
648
For example:
648
649
@@ -698,7 +699,7 @@ type minimize =
698
699
699
700
Default: `true` in production mode, otherwise `false`
700
701
701
-
Tell `html-loader`to minimize HTML.
702
+
Use this option to enable or customize HTML minimization with `html-loader`.
702
703
703
704
#### `boolean`
704
705
@@ -743,7 +744,7 @@ module.exports = {
743
744
744
745
See [html-minifier-terser](https://github.com/DanielRuf/html-minifier-terser)'s documentation for more information on the available options.
745
746
746
-
The default rules can be overridden using the following options in your `webpack.conf.js`
747
+
The default rules can be overridden using the following options in your `webpack.config.js`
747
748
748
749
**webpack.config.js**
749
750
@@ -805,7 +806,7 @@ Default: `true`
805
806
By default, `html-loader` generates JS modules that use the ES modules syntax.
806
807
There are some cases in which using ES modules is beneficial, such as [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).
807
808
808
-
You can enable a CommonJS modules syntax using:
809
+
If you want to generate CommonJS modules instead (e.g., `module.exports =`), set:
809
810
810
811
**webpack.config.js**
811
812
@@ -827,9 +828,9 @@ module.exports = {
827
828
828
829
## Examples
829
830
830
-
### Disable url resolving using the `<!-- webpackIgnore: true -->` comment
831
+
### Disable URL resolving using the `<!-- webpackIgnore: true -->` comment
831
832
832
-
With `<!-- webpackIgnore: true -->` comment, one can disable sources handling for next tag.
833
+
Use the `<!-- webpackIgnore: true -->` comment to prevent html-loader from processing URLs for the next HTML tag. This is useful when you don’t want Webpack to handle asset imports automatically.
833
834
834
835
```html
835
836
<!-- Disabled url handling for the src attribute -->
@@ -1016,7 +1017,9 @@ module.exports = {
1016
1017
1017
1018
### Templating
1018
1019
1019
-
You can use any template system. Below is an example for [handlebars](https://handlebarsjs.com/).
1020
+
You can use any templating engine by leveraging the preprocessor option in html-loader. The preprocessor function receives the file content and the loader context, allowing you to transform the HTML before it’s processed by webpack.
1021
+
1022
+
Below is an example for [handlebars](https://handlebarsjs.com/).
1020
1023
1021
1024
**file.hbs**
1022
1025
@@ -1062,9 +1065,12 @@ module.exports = {
1062
1065
};
1063
1066
```
1064
1067
1068
+
This setup will transform the `file.hbs` template using Handlebars before passing the result to `html-loader`.
1069
+
1065
1070
### PostHTML
1066
1071
1067
-
You can use [PostHTML](https://github.com/posthtml/posthtml) without any additional loaders.
1072
+
You can use [PostHTML](https://github.com/posthtml/posthtml) to transform HTML before it's processed, without needing additional loaders.
1073
+
This is useful for tasks like converting image formats, adding attributes, or restructuring markup.
1068
1074
1069
1075
**file.html**
1070
1076
@@ -1142,7 +1148,8 @@ module.exports = {
1142
1148
1143
1149
## Contributing
1144
1150
1145
-
Please take a moment to read our contributing guidelines if you haven't yet done so.
1151
+
We welcome all contributions!
1152
+
If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
0 commit comments