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
[](https://stackblitz.com/edit/inline-all-assets-to-html?file=README.md)
@@ -5685,15 +5621,17 @@ If you use it yet, remove this legacy loader from your configuration.
5685
5621
Since Webpack 5, you can use the native Webpack [Asset Modules](https://webpack.js.org/guides/asset-modules/),
5686
5622
which are supported by the Bundler Plugin.
5687
5623
5688
-
> [!NOTE]
5689
-
> This requires a couple of extra lines of configuration,
5690
-
> but is faster since it doesn't use extra handlers like `svg-url-loader`.
5624
+
#### Replacement of svg-url-loader options
5691
5625
5692
-
### Use cases
5626
+
- [encoding](https://github.com/bhovhannes/svg-url-loader#encoding) - Use the `?inline` or `?inline=base64` query.
5627
+
- [prefix]() - Use the [output filename](https://webpack.js.org/guides/asset-modules/#custom-output-filename) option.
5628
+
- [limit](https://github.com/bhovhannes/svg-url-loader#limit) - Use the [Rule.parser.dataUrlCondition](https://webpack.js.org/configuration/module/#ruleparserdataurlcondition) option.
5629
+
- [iesafe](https://github.com/bhovhannes/svg-url-loader#iesafe) - The same as by `limit` using `Rule.parser.dataUrlCondition.maxSize=4096`.
5630
+
- [stripdeclarations](https://github.com/bhovhannes/svg-url-loader#stripdeclarations) - we wan't manipulate the SVG content, may be useful to read by [svgo](https://github.com/svg/svgo/issues/836).\
5631
+
Anyway [In XML 1.1, the declaration is mandatory](https://stackoverflow.com/a/7007781/1696030), therefore this option is senseless.
5693
5632
5694
-
#### Import SVG file in JS as output filename.
5695
5633
5696
-
Using default configuration of module rules with `asset/resource`module type, the imported SVG file will contain a output filename.
5634
+
To handle SVG files define the module configuration:
5697
5635
5698
5636
```js
5699
5637
module: {
@@ -5709,75 +5647,51 @@ module: {
5709
5647
}
5710
5648
```
5711
5649
5712
-
The imported `file` contains the hashed output filename.
5650
+
### Import SVG file as output filename.
5651
+
5652
+
Using the module configuration as `asset/resource`, the imported SVG file will contain a output filename.
5653
+
5713
5654
5714
5655
```js
5715
5656
importfilefrom'./image.svg';
5716
5657
5717
5658
console.log(file); // img/image.416b7e1d.svg
5718
5659
```
5719
5660
5720
-
#### Import SVG file in JS as data URL.
5661
+
### Import SVG file as data URL.
5721
5662
5722
-
To import SVG file as the data URL, use the `asset/inline` module type.
5723
-
If you import an SVG file in different ways, you can define a URL query for each module type.
5663
+
The Bundler Plugin supports the `?inline` URL query to force load SVG file as a data URL.
5724
5664
5725
-
For example, use the `?dataurl` query to import a SVG file as data URL:
5665
+
> [!NOTE]
5666
+
> The `inline` query works independent of used module type.
5726
5667
5727
-
```js
5728
-
module: {
5729
-
rules: [
5730
-
{
5731
-
test:/\.svg/i,
5732
-
resourceQuery:/dataurl/, // <= you can define any query as you like
5733
-
type:'asset/inline',
5734
-
},
5735
-
],
5736
-
}
5737
-
```
5668
+
The `inline` query parameter supports values of encoding:
5669
+
- `utf8` - import SVG as UTF-8 data URL (defaults, can be omitted)
5670
+
- `base64` - import SVG as base64-encoded data URL
5738
5671
5739
-
By importing an SVG file using the `?dataurl` query, Webpack generates a base64-encoded data URL.
5672
+
For example, import SVG as UTF-8 data URL:
5740
5673
5741
5674
```js
5742
-
importfilefrom'./image.svg?dataurl'; // <= the `dataurl` query must be defined in Webpack
[](https://stackblitz.com/edit/inline-all-assets-to-html?file=README.md)
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "html-bundler-webpack-plugin",
3
-
"version": "4.12.0-beta.0",
3
+
"version": "4.12.0",
4
4
"description": "Generates complete single-page or multi-page website from source assets. Build-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.",
0 commit comments