vite-plugin-svgr 5.0.0 → 5.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/dist/index.cjs +65 -85
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -10
- package/dist/index.js +41 -45
- package/package.json +19 -11
package/dist/index.cjs
CHANGED
|
@@ -1,87 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
37
17
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let _rollup_pluginutils = require("@rollup/pluginutils");
|
|
24
|
+
let node_fs = require("node:fs");
|
|
25
|
+
node_fs = __toESM(node_fs);
|
|
26
|
+
//#region src/index.ts
|
|
27
|
+
function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude } = {}) {
|
|
28
|
+
const filter = (0, _rollup_pluginutils.createFilter)(include, exclude);
|
|
29
|
+
const postfixRE = /[?#].*$/s;
|
|
30
|
+
return {
|
|
31
|
+
name: "vite-plugin-svgr",
|
|
32
|
+
enforce: "pre",
|
|
33
|
+
async load(id) {
|
|
34
|
+
if (!filter(id)) return;
|
|
35
|
+
const filePath = id.replace(postfixRE, "");
|
|
36
|
+
const svgCode = await node_fs.default.promises.readFile(filePath, "utf8");
|
|
37
|
+
const { transform: svgrTransform } = await import("@svgr/core");
|
|
38
|
+
const { default: jsx } = await import("@svgr/plugin-jsx");
|
|
39
|
+
const componentCode = await svgrTransform(svgCode, svgrOptions, {
|
|
40
|
+
filePath,
|
|
41
|
+
caller: { defaultPlugins: [jsx] }
|
|
42
|
+
});
|
|
43
|
+
if ((this?.meta)?.rolldownVersion != null) {
|
|
44
|
+
/* c8 ignore next */
|
|
45
|
+
const { transformWithOxc } = await import("vite");
|
|
46
|
+
return {
|
|
47
|
+
code: (await transformWithOxc(componentCode, id, {
|
|
48
|
+
lang: "jsx",
|
|
49
|
+
...oxcOptions
|
|
50
|
+
})).code,
|
|
51
|
+
map: null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/* c8 ignore next */
|
|
55
|
+
const { transformWithEsbuild } = await import("vite");
|
|
56
|
+
return {
|
|
57
|
+
code: (await transformWithEsbuild(componentCode, id, {
|
|
58
|
+
loader: "jsx",
|
|
59
|
+
...esbuildOptions
|
|
60
|
+
})).code,
|
|
61
|
+
map: null
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
87
65
|
}
|
|
66
|
+
//#endregion
|
|
67
|
+
module.exports = vitePluginSvgr;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FilterPattern } from "@rollup/pluginutils";
|
|
2
|
+
import { Config } from "@svgr/core";
|
|
3
|
+
import { EsbuildTransformOptions, Plugin, transformWithOxc } from "vite";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
type OxcTransformOptions = NonNullable<Parameters<typeof transformWithOxc>[2]>;
|
|
7
|
+
interface VitePluginSvgrOptions {
|
|
8
|
+
svgrOptions?: Config;
|
|
9
|
+
esbuildOptions?: EsbuildTransformOptions;
|
|
10
|
+
oxcOptions?: OxcTransformOptions;
|
|
11
|
+
exclude?: FilterPattern;
|
|
12
|
+
include?: FilterPattern;
|
|
13
|
+
}
|
|
14
|
+
declare function vitePluginSvgr({
|
|
15
|
+
svgrOptions,
|
|
16
|
+
esbuildOptions,
|
|
17
|
+
oxcOptions,
|
|
18
|
+
include,
|
|
19
|
+
exclude
|
|
20
|
+
}?: VitePluginSvgrOptions): Plugin;
|
|
21
|
+
export = vitePluginSvgr;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { FilterPattern } from "@rollup/pluginutils";
|
|
2
|
+
import { Config } from "@svgr/core";
|
|
3
|
+
import { EsbuildTransformOptions, Plugin, transformWithOxc } from "vite";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
type OxcTransformOptions = NonNullable<Parameters<typeof transformWithOxc>[2]>;
|
|
7
|
+
interface VitePluginSvgrOptions {
|
|
8
|
+
svgrOptions?: Config;
|
|
9
|
+
esbuildOptions?: EsbuildTransformOptions;
|
|
10
|
+
oxcOptions?: OxcTransformOptions;
|
|
11
|
+
exclude?: FilterPattern;
|
|
12
|
+
include?: FilterPattern;
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
declare function vitePluginSvgr({
|
|
15
|
+
svgrOptions,
|
|
16
|
+
esbuildOptions,
|
|
17
|
+
oxcOptions,
|
|
18
|
+
include,
|
|
19
|
+
exclude
|
|
20
|
+
}?: VitePluginSvgrOptions): Plugin;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { vitePluginSvgr as default };
|
package/dist/index.js
CHANGED
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
import { createFilter } from "@rollup/pluginutils";
|
|
2
|
-
import { transform as svgrTransform } from "@svgr/core";
|
|
3
|
-
import jsx from "@svgr/plugin-jsx";
|
|
4
2
|
import fs from "node:fs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
map: null, // TODO:
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
};
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude } = {}) {
|
|
5
|
+
const filter = createFilter(include, exclude);
|
|
6
|
+
const postfixRE = /[?#].*$/s;
|
|
7
|
+
return {
|
|
8
|
+
name: "vite-plugin-svgr",
|
|
9
|
+
enforce: "pre",
|
|
10
|
+
async load(id) {
|
|
11
|
+
if (!filter(id)) return;
|
|
12
|
+
const filePath = id.replace(postfixRE, "");
|
|
13
|
+
const svgCode = await fs.promises.readFile(filePath, "utf8");
|
|
14
|
+
const { transform: svgrTransform } = await import("@svgr/core");
|
|
15
|
+
const { default: jsx } = await import("@svgr/plugin-jsx");
|
|
16
|
+
const componentCode = await svgrTransform(svgCode, svgrOptions, {
|
|
17
|
+
filePath,
|
|
18
|
+
caller: { defaultPlugins: [jsx] }
|
|
19
|
+
});
|
|
20
|
+
if ((this?.meta)?.rolldownVersion != null) {
|
|
21
|
+
/* c8 ignore next */
|
|
22
|
+
const { transformWithOxc } = await import("vite");
|
|
23
|
+
return {
|
|
24
|
+
code: (await transformWithOxc(componentCode, id, {
|
|
25
|
+
lang: "jsx",
|
|
26
|
+
...oxcOptions
|
|
27
|
+
})).code,
|
|
28
|
+
map: null
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/* c8 ignore next */
|
|
32
|
+
const { transformWithEsbuild } = await import("vite");
|
|
33
|
+
return {
|
|
34
|
+
code: (await transformWithEsbuild(componentCode, id, {
|
|
35
|
+
loader: "jsx",
|
|
36
|
+
...esbuildOptions
|
|
37
|
+
})).code,
|
|
38
|
+
map: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
48
42
|
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { vitePluginSvgr as default };
|
package/package.json
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
7
|
-
"
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.cts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
12
19
|
},
|
|
13
20
|
"./client": {
|
|
14
21
|
"types": "./client.d.ts"
|
|
15
22
|
}
|
|
16
23
|
},
|
|
17
24
|
"scripts": {
|
|
18
|
-
"dev": "
|
|
19
|
-
"build": "
|
|
25
|
+
"dev": "tsdown --watch",
|
|
26
|
+
"build": "tsdown",
|
|
20
27
|
"prepare": "npm run build",
|
|
21
28
|
"test": "node --import tsx --test test/**/*.test.ts",
|
|
22
29
|
"test:e2e": "node --import tsx --test test/process.test.ts",
|
|
@@ -36,10 +43,11 @@
|
|
|
36
43
|
"author": "Rongjian Zhang",
|
|
37
44
|
"license": "MIT",
|
|
38
45
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"c8": "^
|
|
46
|
+
"@types/node": "^25.5.0",
|
|
47
|
+
"c8": "^11.0.0",
|
|
48
|
+
"tsdown": "^0.21.7",
|
|
41
49
|
"tsx": "^4.21.0",
|
|
42
|
-
"typescript": "^
|
|
50
|
+
"typescript": "^6.0.2",
|
|
43
51
|
"vite": "^8.0.3",
|
|
44
52
|
"vite3": "npm:vite@3.2.11",
|
|
45
53
|
"vite4": "npm:vite@4.5.14",
|
|
@@ -52,7 +60,7 @@
|
|
|
52
60
|
"vite": ">=3.0.0"
|
|
53
61
|
},
|
|
54
62
|
"dependencies": {
|
|
55
|
-
"@rollup/pluginutils": "^5.
|
|
63
|
+
"@rollup/pluginutils": "^5.3.0",
|
|
56
64
|
"@svgr/core": "^8.1.0",
|
|
57
65
|
"@svgr/plugin-jsx": "^8.1.0"
|
|
58
66
|
},
|