vite-plugin-svgr 4.3.0 → 5.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.
- package/README.md +5 -0
- package/dist/index.cjs +49 -24
- package/dist/index.d.ts +6 -6
- package/dist/index.js +32 -17
- package/package.json +42 -10
package/README.md
CHANGED
|
@@ -55,6 +55,11 @@ svgr({
|
|
|
55
55
|
// ...
|
|
56
56
|
},
|
|
57
57
|
|
|
58
|
+
// oxc options, used by rolldown / vite 8+
|
|
59
|
+
oxcOptions: {
|
|
60
|
+
// ...
|
|
61
|
+
},
|
|
62
|
+
|
|
58
63
|
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should include.
|
|
59
64
|
include: "**/*.svg?react",
|
|
60
65
|
|
package/dist/index.cjs
CHANGED
|
@@ -15,48 +15,73 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.default = vitePluginSvgr;
|
|
30
40
|
const pluginutils_1 = require("@rollup/pluginutils");
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
41
|
+
const core_1 = require("@svgr/core");
|
|
42
|
+
const plugin_jsx_1 = __importDefault(require("@svgr/plugin-jsx"));
|
|
43
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
44
|
+
function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
34
45
|
const filter = (0, pluginutils_1.createFilter)(include, exclude);
|
|
35
46
|
const postfixRE = /[?#].*$/s;
|
|
36
47
|
return {
|
|
37
48
|
name: "vite-plugin-svgr",
|
|
38
49
|
enforce: "pre", // to override `vite:asset`'s behavior
|
|
39
50
|
async load(id) {
|
|
40
|
-
if (filter(id)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (!filter(id)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const filePath = id.replace(postfixRE, "");
|
|
55
|
+
const svgCode = await node_fs_1.default.promises.readFile(filePath, "utf8");
|
|
56
|
+
const componentCode = await (0, core_1.transform)(svgCode, svgrOptions, {
|
|
57
|
+
filePath,
|
|
58
|
+
caller: {
|
|
59
|
+
defaultPlugins: [plugin_jsx_1.default],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const meta = this?.meta;
|
|
63
|
+
if (meta?.rolldownVersion != null) {
|
|
64
|
+
/* c8 ignore next */
|
|
65
|
+
const { transformWithOxc } = await Promise.resolve().then(() => __importStar(require("vite")));
|
|
66
|
+
const res = await transformWithOxc(componentCode, id, {
|
|
67
|
+
lang: "jsx",
|
|
68
|
+
...oxcOptions,
|
|
54
69
|
});
|
|
55
70
|
return {
|
|
56
71
|
code: res.code,
|
|
57
72
|
map: null, // TODO:
|
|
58
73
|
};
|
|
59
74
|
}
|
|
75
|
+
/* c8 ignore next */
|
|
76
|
+
const { transformWithEsbuild } = await Promise.resolve().then(() => __importStar(require("vite")));
|
|
77
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
78
|
+
loader: "jsx",
|
|
79
|
+
...esbuildOptions,
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
code: res.code,
|
|
83
|
+
map: null, // TODO:
|
|
84
|
+
};
|
|
60
85
|
},
|
|
61
86
|
};
|
|
62
87
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FilterPattern } from "@rollup/pluginutils";
|
|
2
|
-
import type
|
|
3
|
-
import type { Plugin } from "vite";
|
|
4
|
-
import { transformWithEsbuild } from "vite";
|
|
1
|
+
import { type FilterPattern } from "@rollup/pluginutils";
|
|
2
|
+
import { type Config } from "@svgr/core";
|
|
3
|
+
import type { EsbuildTransformOptions, Plugin, TransformOptions as OxcTransformOptions } from "vite";
|
|
5
4
|
export interface VitePluginSvgrOptions {
|
|
6
5
|
svgrOptions?: Config;
|
|
7
|
-
esbuildOptions?:
|
|
6
|
+
esbuildOptions?: EsbuildTransformOptions;
|
|
7
|
+
oxcOptions?: OxcTransformOptions;
|
|
8
8
|
exclude?: FilterPattern;
|
|
9
9
|
include?: FilterPattern;
|
|
10
10
|
}
|
|
11
|
-
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
|
|
11
|
+
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,48 @@
|
|
|
1
1
|
import { createFilter } from "@rollup/pluginutils";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { transform as svgrTransform } from "@svgr/core";
|
|
3
|
+
import jsx from "@svgr/plugin-jsx";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
5
6
|
const filter = createFilter(include, exclude);
|
|
6
7
|
const postfixRE = /[?#].*$/s;
|
|
7
8
|
return {
|
|
8
9
|
name: "vite-plugin-svgr",
|
|
9
10
|
enforce: "pre", // to override `vite:asset`'s behavior
|
|
10
11
|
async load(id) {
|
|
11
|
-
if (filter(id)) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
if (!filter(id)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const filePath = id.replace(postfixRE, "");
|
|
16
|
+
const svgCode = await fs.promises.readFile(filePath, "utf8");
|
|
17
|
+
const componentCode = await svgrTransform(svgCode, svgrOptions, {
|
|
18
|
+
filePath,
|
|
19
|
+
caller: {
|
|
20
|
+
defaultPlugins: [jsx],
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const meta = this?.meta;
|
|
24
|
+
if (meta?.rolldownVersion != null) {
|
|
25
|
+
/* c8 ignore next */
|
|
26
|
+
const { transformWithOxc } = await import("vite");
|
|
27
|
+
const res = await transformWithOxc(componentCode, id, {
|
|
28
|
+
lang: "jsx",
|
|
29
|
+
...oxcOptions,
|
|
25
30
|
});
|
|
26
31
|
return {
|
|
27
32
|
code: res.code,
|
|
28
33
|
map: null, // TODO:
|
|
29
34
|
};
|
|
30
35
|
}
|
|
36
|
+
/* c8 ignore next */
|
|
37
|
+
const { transformWithEsbuild } = await import("vite");
|
|
38
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
39
|
+
loader: "jsx",
|
|
40
|
+
...esbuildOptions,
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
code: res.code,
|
|
44
|
+
map: null, // TODO:
|
|
45
|
+
};
|
|
31
46
|
},
|
|
32
47
|
};
|
|
33
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
11
|
+
"import": "./dist/index.js"
|
|
13
12
|
},
|
|
14
13
|
"./client": {
|
|
15
14
|
"types": "./client.d.ts"
|
|
@@ -17,8 +16,12 @@
|
|
|
17
16
|
},
|
|
18
17
|
"scripts": {
|
|
19
18
|
"dev": "tsc --watch",
|
|
20
|
-
"build": "tsc
|
|
21
|
-
"prepare": "npm run build"
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"test": "node --import tsx --test test/**/*.test.ts",
|
|
22
|
+
"test:e2e": "node --import tsx --test test/process.test.ts",
|
|
23
|
+
"test:coverage": "c8 node --import tsx --test test/**/*.test.ts",
|
|
24
|
+
"test:compat": "node scripts/test-vite-compat.js"
|
|
22
25
|
},
|
|
23
26
|
"repository": "pd4d10/vite-plugin-svgr",
|
|
24
27
|
"files": [
|
|
@@ -33,16 +36,45 @@
|
|
|
33
36
|
"author": "Rongjian Zhang",
|
|
34
37
|
"license": "MIT",
|
|
35
38
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"
|
|
39
|
+
"@types/node": "^24.3.0",
|
|
40
|
+
"c8": "^10.1.3",
|
|
41
|
+
"tsx": "^4.21.0",
|
|
42
|
+
"typescript": "^5.9.2",
|
|
43
|
+
"vite": "^8.0.3",
|
|
44
|
+
"vite3": "npm:vite@3.2.11",
|
|
45
|
+
"vite4": "npm:vite@4.5.14",
|
|
46
|
+
"vite5": "npm:vite@5.4.21",
|
|
47
|
+
"vite6": "npm:vite@6.4.1",
|
|
48
|
+
"vite7": "npm:vite@7.3.1",
|
|
49
|
+
"vite8": "npm:vite@8.0.3"
|
|
38
50
|
},
|
|
39
51
|
"peerDependencies": {
|
|
40
|
-
"vite": ">=
|
|
52
|
+
"vite": ">=3.0.0"
|
|
41
53
|
},
|
|
42
54
|
"dependencies": {
|
|
43
|
-
"@rollup/pluginutils": "^5.
|
|
55
|
+
"@rollup/pluginutils": "^5.2.0",
|
|
44
56
|
"@svgr/core": "^8.1.0",
|
|
45
57
|
"@svgr/plugin-jsx": "^8.1.0"
|
|
46
58
|
},
|
|
47
|
-
"packageManager": "pnpm@
|
|
59
|
+
"packageManager": "pnpm@10.15.0+sha256.84c19e788d7d7ee248e4a6b7152f8ebba0f4fe7380a5f443ca17d76c030052d2",
|
|
60
|
+
"c8": {
|
|
61
|
+
"all": true,
|
|
62
|
+
"include": [
|
|
63
|
+
"src/**/*.ts"
|
|
64
|
+
],
|
|
65
|
+
"exclude": [
|
|
66
|
+
"dist/**",
|
|
67
|
+
"codemods/**",
|
|
68
|
+
"test/**"
|
|
69
|
+
],
|
|
70
|
+
"reporter": [
|
|
71
|
+
"text",
|
|
72
|
+
"lcov"
|
|
73
|
+
],
|
|
74
|
+
"check-coverage": true,
|
|
75
|
+
"branches": 100,
|
|
76
|
+
"functions": 100,
|
|
77
|
+
"lines": 100,
|
|
78
|
+
"statements": 100
|
|
79
|
+
}
|
|
48
80
|
}
|