svg-sprite-generation-loader 0.0.2 → 1.0.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 +9 -3
  2. package/index.js +6 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -69,6 +69,12 @@ Plugin options:
69
69
  | spriteFilePath | `string` | `sprite.svg` | Path to sprite file.<br /> `webpack.output.path` <br /> is included |
70
70
  | svgo | object | default preset with disabled `removeUselessDefs`, `removeViewBox` and `cleanupIDs` plugins | [svgo](https://github.com/svg/svgo) config object |
71
71
 
72
+ Loader options:
73
+
74
+ | Name | Type | Default value | Description |
75
+ | -------- | -------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------ |
76
+ | symbolId | `function(iconPath)` | Icon filename (without extension). For example symbolId for `file1.svg` file will be `file1` | `<symbol>`&nbsp;`id` attribute value |
77
+
72
78
  ## Usage:
73
79
 
74
80
  In your webpack config:
@@ -96,9 +102,9 @@ module.exports = {
96
102
  In some source code:
97
103
 
98
104
  ```jsx
99
- import iconAttributes from "path/to/some/icon-file-name.svg";
105
+ import iconData from "path/to/some/icon-file-name.svg";
100
106
 
101
- <svg {...iconAttributes}>
102
- <use href="path/to/sprite/filename.svg#icon-file-name" />
107
+ <svg {...iconData.attributes}>
108
+ <use href={`path/to/sprite/filename.svg#${iconData.symbolId}`} />
103
109
  </svg>;
104
110
  ```
package/index.js CHANGED
@@ -5,13 +5,17 @@ const parseSvg = require("./utils/parseSvg.js");
5
5
 
6
6
  module.exports = function (source) {
7
7
  const { attributes, content } = parseSvg(source);
8
- const symbolId = path.basename(this.resourcePath, ".svg");
8
+
9
+ const options = this.getOptions();
10
+ const symbolId = options.symbolId
11
+ ? options.symbolId(this.resourcePath)
12
+ : path.basename(this.resourcePath, ".svg");
9
13
 
10
14
  if (this.target === "web") {
11
15
  svgSpriteState.addSpriteIcon({ symbolId, attributes, content });
12
16
  }
13
17
 
14
18
  return `
15
- export default ${JSON.stringify(attributes)}
19
+ export default ${JSON.stringify({ symbolId, attributes })}
16
20
  `;
17
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svg-sprite-generation-loader",
3
- "version": "0.0.2",
3
+ "version": "1.0.0",
4
4
  "description": "Webpack loader for generating external svg symbol sprite files",
5
5
  "main": "index.js",
6
6
  "scripts": {