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: CHANGELOG.md
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,11 @@
1
+
## v2.3.0
2
+
3
+
* BREAKING CHANGE: On the webpack configuration file the `svgoConfig` option must now go inside `HtmlWebpackInlineSVGPlugin({})` instead of `HtmlWebpackPlugin({})`. An error is thrown at webpack build time otherwise.
4
+
* The defaults for the `svgo` module aren't hardcoded anymore and –excepting the `cleanupIDs` option– the defaults are now set by the own module `svgo` and not `html-webpack-inline-svg-plugin`.
5
+
1
6
## v2.2.0
2
7
3
-
*_Ability added to load SVGs from an URL (`<img inline src="https://host.com/image.svg">`)._
8
+
*Ability added to load SVGs from an URL (`<img inline src="https://host.com/image.svg">`).
1.[Incorrect File Paths And URLs](#incorrect-file-paths-and-urls)
16
+
1.[Default Config](#default-config)
17
+
1.[Incorrect File Paths Or URLs](#incorrect-file-paths-or-urls)
18
18
1.[Duplicated Attributes](#duplicated-attributes)
19
19
1.[Config](#config)
20
20
1.[Versions](#versions)
@@ -28,11 +28,11 @@ By inlining SVGs you can combine them with techniques such as: [Icon System with
28
28
29
29
As of version 1.0.0 **by default** this plugin processes SVG files after all template and image files have been written to their corresponding output directory. This allows it to work alongside loaders, after webpack resolves all file locations.
30
30
31
-
> Please note: to use **aliases** you will need to install loaders to resolve your svg paths and parse the templates html. More info is provided below: [Getting To Your SVGs](#getting-to-your-svgs).
31
+
> Please note: to use **aliases** you will need to install loaders to resolve your svg paths and parse the templates html. Check [Getting To Your SVGs](#getting-to-your-svgs) section for more info.
32
32
33
-
**As of version 1.1.0** the plugin can also be run prior to the output of your templates. This allows you to reference image files from the root of your project which can help with getting to certain files, i.e. within your `node_modules` directory. More info is provided below: [Setting runPreEmit option](#setting-runpreemit-option).
33
+
**As of version 1.1.0** the plugin can also be run prior to the output of your templates. This allows you to reference image files from the root of your project which can help with getting to certain files, i.e. within your `node_modules` directory. More info is provided below: [Setting `runPreEmit` option](#setting-runpreemit-option).
34
34
35
-
The plugin relies on [svgo](https://github.com/svg/svgo) to optimise SVGs. You can configure it's settings, check[Config](#config) for more details.
35
+
The plugin relies on [SVGO](https://github.com/svg/svgo) to optimise SVGs. Check[Config](#config) for more details.
36
36
37
37
38
38
## Features
@@ -48,13 +48,15 @@ The plugin relies on [svgo](https://github.com/svg/svgo) to optimise SVGs. You c
Add `img` tags with `inline` attribute and `.svg` file as src to your template/s that the html-webpack-plugin is processing (the default is `index.html`).
79
+
Add `img` tags with `inline` attribute and `.svg` file as `src` to your template/s that the html-webpack-plugin is processing (the default is `index.html`).
78
80
79
81
```html
80
82
<!-- Works: below img tag will be removed and replaced by the content of the svg in its src -->
@@ -97,7 +99,7 @@ There are three ways of working with your `<img>` **src** attributes and this pl
97
99
98
100
1.**Alternatively use loaders** such as [html-loader](https://github.com/webpack-contrib/html-loader) to parse the html templates, and [file-loader](https://github.com/webpack-contrib/file-loader) or something similar, to resolve the paths of your `img` tags `src` attributes. As the plugin works after webpack has emitted all its assets and *html-webpack-plugin* has output your templates, it will read the SVGs that webpack places in your output directory, and replace any **inlined img tags** with this content.
99
101
100
-
1.**Set the `runPreEmit` flag** and reference files relative to your `package.json` file. This feature is only available with version >= 1.1.0. More info is provided below: [Setting runPreEmit option](#setting-runpreemit-option).
102
+
1.**Set the `runPreEmit` flag** and reference files relative to your `package.json` file. This feature is only available with version >= 1.1.0. Check [Config](#config) and the `runPreEmit` option for more info.
With the above structure inlining `icons.svg` would look like:
122
+
119
123
```html
120
124
<imginlinesrc="images/icons.svg">
121
125
```
122
126
123
127
If an alias was in place for the images directory, i.e.
128
+
124
129
```javascript
125
130
'img':path.join(__dirname, 'src', 'images')
126
131
```
132
+
127
133
Then the svg can be inlined with: `<img inline src="~img/icons.svg">`. This method would require the use of **loaders** on your templates as shown above in point 2.
128
134
129
-
### Incorrect file paths and URLs
135
+
### Incorrect file paths or URLs
136
+
130
137
If for any reason the path to a local SVG file is incorrect, or the file fails to be read, or an image retrieved with an URL fails to download, the webpack build process will fail with an error, like `ENOENT`.
131
138
132
139
### Duplicated attributes
140
+
133
141
All the attributes of a `<img/>` element excepting `src` and `inline` will be copied to the inlined `<svg/>` element. Attributes like `id` or `class` will be copied to the resulting root of the `<svg/>` element and if the original SVG file already had these attributes they will be duplicated (and not replaced) on the resulting `<svg/>` element, though the attributes coming from the `<img/>` will appear first and [any subsequent duplicated attribute from the original SVG will be ignored by the browser](https://stackoverflow.com/questions/26341507/can-an-html-element-have-the-same-attribute-twice).
The broswer will use `id=""myImageIMG"` and not `id="myImageSVG"`. It's however a better approach if you avoid having any duplicated attribute at all and only putting the required ones on the `<img>` element.
157
+
The broswer will use `id="myImageIMG"` and not `id="myImageSVG"`. It's however a better approach if you avoid having any duplicated attribute at all and only putting the required ones on the `<img>` element.
150
158
151
159
152
160
## Config
@@ -211,21 +219,29 @@ The plugin accepts the below options:
211
219
</div>
212
220
```
213
221
214
-
-`svgoConfig`: defaults to `undefinded`. to configure SVGO (module used to optimise your SVGs), add an `svgoConfig` object to your `html-webpack-plugin` config:
222
+
-`svgoConfig`: defaults to `[]`. [SVGO](https://github.com/svg/svgo) is used to optimise the SVGs inlined. You can configure SVGO by setting this `svgoConfig` array with the [SVGO plugins](https://github.com/svg/svgo#what-it-can-do) you need in the same way it's done in this [SVGO official Node.js example](https://github.com/svg/svgo/blob/master/examples/test.js).
223
+
224
+
Note `svgoConfig` is an array of `Object`s that will be assigned to the `.plugins` SVGO config variable by `html-webpack-inline-svg-plugin`. You don't need to pass an `Object` with a `plugins` property assigned an array of SVGO plugins, just pass the array:
215
225
216
226
```javascript
217
227
plugins: [
218
-
newHtmlWebpackPlugin({
219
-
svgoConfig: {
220
-
removeTitle:false,
221
-
removeViewBox:true,
222
-
},
223
-
}),
224
-
newHtmlWebpackInlineSVGPlugin()
228
+
newHtmlWebpackPlugin(),
229
+
newHtmlWebpackInlineSVGPlugin({
230
+
svgoConfig: [
231
+
{
232
+
removeViewBox:false
233
+
},
234
+
{
235
+
inlineStyles: {
236
+
onlyMatchedOnce:false
237
+
}
238
+
}
239
+
]
240
+
})
225
241
]
226
242
```
227
243
228
-
For a full list of the SVGO config (default) params we are using check out: [svgo-config.js](svgo-config.js). The config you set is merged with our defaults, it does not replace it.
244
+
`html-webpack-inline-svg-plugin` modifies one SVGO default: `cleanupIDs`, from `true` to `false`, since IDs allow to reference individual symbols. You can still override this or any other SVGO plugin default configuration with this `svgoConfig` option.
229
245
230
246
231
247
## Versions
@@ -245,9 +261,9 @@ For webpack 3 and html-webpack-plugin v3 support use v1.3.0 of this package.
245
261
246
262
## Contribution
247
263
248
-
You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests.
264
+
You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature must be covered by tests.
249
265
250
-
I'm happy for someone to take over the project as I don't find myself using it anylonger due to changes in workflow. Therefore others are likely in a better position to support this project and roll out the right enhancements.
266
+
I'm happy for someone to take over the project as I don't find myself using it any longer due to changes in workflow. Therefore others are likely to be in a better position to support this project and roll out the right enhancements.
thrownewError('html-webpack-inline-svg-plugin: on your webpack configuration file svgoConfig option must now go inside HtmlWebpackInlineSVGPlugin({}) instead of HtmlWebpackPlugin({}). Also note the SVGO configuration format has changed and the one you had will need tweaking: https://github.com/theGC/html-webpack-inline-svg-plugin#config')
194
+
}
196
195
197
196
}
198
197
@@ -453,20 +452,9 @@ class HtmlWebpackInlineSVGPlugin {
0 commit comments