rspack-svg-sprite-loader-plugin 0.1.2

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 ADDED
@@ -0,0 +1,17 @@
1
+ # SVG Sprite Plugin for Rspack
2
+
3
+ Adds a module rule that processes SVG files through the "svg-sprite-loader".
4
+ Uses the standard Rspack plugin API (apply method).
5
+
6
+ ## Usage:
7
+
8
+ ```js
9
+ import { SvgSpritePlugin } from "rspack-svg-sprite-loader-plugin";
10
+
11
+ plugins: [
12
+ new SvgSpritePlugin({
13
+ symbolId: "icon-[name]",
14
+ include: [path.resolve(__dirname, "src/ui/Icon/assets")],
15
+ }),
16
+ ];
17
+ ```
@@ -0,0 +1,16 @@
1
+ import { Compiler, RuleSetRule } from "@rspack/core";
2
+
3
+ //#region src/index.d.ts
4
+ declare class SvgSpritePlugin {
5
+ options: {
6
+ symbolId: string;
7
+ test: RegExp;
8
+ include: RuleSetRule["include"];
9
+ exclude: RuleSetRule["exclude"];
10
+ };
11
+ constructor(options?: {});
12
+ apply(compiler: Compiler): void;
13
+ }
14
+ //#endregion
15
+ export { SvgSpritePlugin };
16
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAGa,eAAA;EACX,OAAA;IACE,QAAA;IACA,IAAA,EAAM,MAAA;IACN,OAAA,EAAS,WAAA;IACT,OAAA,EAAS,WAAA;EAAA;cAGC,OAAA;EAUZ,KAAA,CAAM,QAAA,EAAU,QAAA;AAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import path from "node:path";
2
+
3
+ //#region src/index.ts
4
+ var SvgSpritePlugin = class {
5
+ options;
6
+ constructor(options = {}) {
7
+ this.options = {
8
+ symbolId: "icon-[name]",
9
+ test: /\.svg$/,
10
+ include: [],
11
+ exclude: [],
12
+ ...options
13
+ };
14
+ }
15
+ apply(compiler) {
16
+ const { symbolId, test, include, exclude } = this.options;
17
+ compiler.options.module.rules.push({
18
+ test,
19
+ include,
20
+ exclude,
21
+ use: [{
22
+ loader: path.resolve(__dirname, "loader.cjs"),
23
+ options: { symbolId }
24
+ }],
25
+ type: "javascript/auto"
26
+ });
27
+ }
28
+ };
29
+
30
+ //#endregion
31
+ export { SvgSpritePlugin };
32
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { Compiler, RuleSetRule } from \"@rspack/core\";\n\nexport class SvgSpritePlugin {\n options: {\n symbolId: string;\n test: RegExp;\n include: RuleSetRule[\"include\"];\n exclude: RuleSetRule[\"exclude\"];\n };\n\n constructor(options = {}) {\n this.options = {\n symbolId: \"icon-[name]\",\n test: /\\.svg$/,\n include: [],\n exclude: [],\n ...options,\n };\n }\n\n apply(compiler: Compiler) {\n const { symbolId, test, include, exclude } = this.options;\n\n compiler.options.module.rules.push({\n test,\n include,\n exclude,\n use: [\n {\n loader: path.resolve(__dirname, \"loader.cjs\"),\n options: { symbolId },\n },\n ],\n type: \"javascript/auto\",\n });\n }\n}\n"],"mappings":";;;AAGA,IAAa,kBAAb,MAA6B;CAC3B;CAOA,YAAY,UAAU,EAAE,EAAE;AACxB,OAAK,UAAU;GACb,UAAU;GACV,MAAM;GACN,SAAS,EAAE;GACX,SAAS,EAAE;GACX,GAAG;GACJ;;CAGH,MAAM,UAAoB;EACxB,MAAM,EAAE,UAAU,MAAM,SAAS,YAAY,KAAK;AAElD,WAAS,QAAQ,OAAO,MAAM,KAAK;GACjC;GACA;GACA;GACA,KAAK,CACH;IACE,QAAQ,KAAK,QAAQ,WAAW,aAAa;IAC7C,SAAS,EAAE,UAAU;IACtB,CACF;GACD,MAAM;GACP,CAAC"}
@@ -0,0 +1,21 @@
1
+ const svgSpriteLoader = require("svg-sprite-loader");
2
+
3
+ module.exports = function (content) {
4
+ const compilation = this._compilation;
5
+
6
+ if (compilation && compilation.moduleGraph) {
7
+ const { getIssuer } = compilation.moduleGraph;
8
+
9
+ if (getIssuer) {
10
+ compilation.moduleGraph.getIssuer = function (...args) {
11
+ try {
12
+ return getIssuer.apply(this, args);
13
+ } catch {
14
+ return null;
15
+ }
16
+ };
17
+ }
18
+ }
19
+
20
+ return svgSpriteLoader.call(this, content);
21
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "rspack-svg-sprite-loader-plugin",
3
+ "description": "SVG Sprite Plugin for Rspack",
4
+ "version": "0.1.2",
5
+ "private": false,
6
+ "type": "module",
7
+ "author": "peakercope <peakercope@gmail.com> (https://github.com/peakercope)",
8
+ "license": "MIT",
9
+ "homepage": "https://github.com/peakercope/rspack-svg-sprite-loader-plugin",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/peakercope/rspack-svg-sprite-loader-plugin.git"
13
+ },
14
+ "keywords": [
15
+ "rspack",
16
+ "plugin",
17
+ "svg-sprite-loader",
18
+ "rspack-svg-sprite-loader-plugin"
19
+ ],
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mts"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "dev": "tsdown --watch ./src",
34
+ "build": "tsc && tsdown",
35
+ "check": "biome check",
36
+ "check:write": "biome check --write",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest",
39
+ "changelog": "git-cliff --config ./scripts/git-cliff.toml --output CHANGELOG.md",
40
+ "release": "np",
41
+ "release:all": "npm run build && npm run publish"
42
+ },
43
+ "devDependencies": {
44
+ "@biomejs/biome": "2.3.15",
45
+ "@types/node": "^25.2.3",
46
+ "git-cliff": "2.12.0",
47
+ "np": "11.0.2",
48
+ "tsdown": "0.20.3",
49
+ "typescript": "5.9.3",
50
+ "vitest": "4.0.18"
51
+ },
52
+ "dependencies": {
53
+ "svg-sprite-loader": "^6.0.11"
54
+ },
55
+ "peerDependencies": {
56
+ "@rspack/core": "^1.7.6"
57
+ }
58
+ }