svg-sprite-generation-loader 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/plugin.js +17 -2
package/README.md
CHANGED
|
@@ -105,6 +105,6 @@ import iconData from 'path/to/some/icon-file-name.svg';
|
|
|
105
105
|
| Name | Type | Default value | Description |
|
|
106
106
|
| -------------- | -------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
107
107
|
| symbolId | `string` \| `function` | `"[name]"` | Sprite item (single icon) `<symbol>` `id` attribute value.<br />`string` or `function` that takes the file path of the original icon as an argument and returns `string`.<br /><br />You can use [interpolateName](https://github.com/webpack/loader-utils#interpolatename) patterns.<br /> Default value (`"[name]"`) is equal to icon filename (without extension). For example, by default symbolId for `file1.svg` file will be `file1` |
|
|
108
|
-
| spriteFilePath | `string` | `sprite.svg` | Path to sprite file.<br /> `webpack.output.path` is included
|
|
108
|
+
| spriteFilePath | `string` | `sprite.svg` | Path to sprite file.<br /> `webpack.output.path` is included. You can use [interpolateName](https://github.com/webpack/loader-utils#interpolatename) patterns. |
|
|
109
109
|
| svgoOptimize | `boolean` \| `object` | `true` | Enable/Disable/Customize source svg file optimization with [svgo.optimize](https://github.com/svg/svgo#optimize). The following options are used by default: <br /><pre>`{`<br /> `plugins: [`<br /> `{`<br /> `name: 'preset-default',`<br /> `params: {`<br /> `overrides: {`<br /> `removeViewBox: false,`<br /> `},`<br /> `},`<br /> `},`<br /> `'removeXMLNS',`<br /> `],`<br />`}`</pre> You can disable it completely (by passing `false`) or use your own configuration (see [svgo docs](https://github.com/svg/svgo#optimize)) |
|
|
110
110
|
| **addContent** | `boolean` | `false` | Add svg content as property to transformed svg object (may increase bundle size when enabled) |
|
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const loaderUtils = require('loader-utils');
|
|
1
2
|
const svgSpriteState = require('./utils/spriteState');
|
|
2
3
|
|
|
3
4
|
class SvgSpriteGeneratorPlugin {
|
|
@@ -24,9 +25,23 @@ class SvgSpriteGeneratorPlugin {
|
|
|
24
25
|
() => {
|
|
25
26
|
if (compilation.options.loader.target === 'web') {
|
|
26
27
|
Object.keys(svgSpriteState.sprites).forEach((spriteFilePath) => {
|
|
27
|
-
|
|
28
|
+
const spriteContent = svgSpriteState.getSpriteContent(
|
|
29
|
+
spriteFilePath,
|
|
30
|
+
this.params
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const interpolatedPath = loaderUtils.interpolateName(
|
|
34
|
+
{ resourcePath: spriteFilePath },
|
|
28
35
|
spriteFilePath,
|
|
29
|
-
|
|
36
|
+
{
|
|
37
|
+
context: compilation.options.context,
|
|
38
|
+
content: spriteContent,
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
compilation.emitAsset(
|
|
43
|
+
interpolatedPath,
|
|
44
|
+
new RawSource(spriteContent)
|
|
30
45
|
);
|
|
31
46
|
});
|
|
32
47
|
}
|