svg-sprite-generation-loader 2.1.2 → 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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. 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`&nbsp;\|&nbsp;`function` | `"[name]"` | Sprite item (single icon) `<symbol>`&nbsp;`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 />&nbsp;&nbsp;`plugins: [`<br />&nbsp;&nbsp;&nbsp;&nbsp;`{`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`name: 'preset-default',`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`params: {`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`overrides: {`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`removeViewBox: false,`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`},`<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`},`<br />&nbsp;&nbsp;&nbsp;&nbsp;`},`<br />&nbsp;&nbsp;&nbsp;&nbsp;`'removeXMLNS',`<br />&nbsp;&nbsp;`],`<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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svg-sprite-generation-loader",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Webpack loader for generating external svg symbol sprite files",
5
5
  "main": "index.js",
6
6
  "scripts": {
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
- compilation.emitAsset(
28
+ const spriteContent = svgSpriteState.getSpriteContent(
29
+ spriteFilePath,
30
+ this.params
31
+ );
32
+
33
+ const interpolatedPath = loaderUtils.interpolateName(
34
+ { resourcePath: spriteFilePath },
28
35
  spriteFilePath,
29
- new RawSource(svgSpriteState.getSpriteContent(spriteFilePath, this.params))
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
  }