vite-plugin-svgr 4.5.0 → 5.1.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.d.ts +7 -5
- package/dist/index.js +31 -25
- package/package.json +40 -8
- package/dist/index.cjs +0 -81
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.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { FilterPattern } from "@rollup/pluginutils";
|
|
1
|
+
import { type FilterPattern } from "@rollup/pluginutils";
|
|
2
2
|
import type { Config } from "@svgr/core";
|
|
3
|
-
import type { Plugin } from "vite";
|
|
4
|
-
|
|
3
|
+
import type { EsbuildTransformOptions, Plugin, transformWithOxc } from "vite";
|
|
4
|
+
type OxcTransformOptions = NonNullable<Parameters<typeof transformWithOxc>[2]>;
|
|
5
5
|
export interface VitePluginSvgrOptions {
|
|
6
6
|
svgrOptions?: Config;
|
|
7
|
-
esbuildOptions?:
|
|
7
|
+
esbuildOptions?: EsbuildTransformOptions;
|
|
8
|
+
oxcOptions?: OxcTransformOptions;
|
|
8
9
|
exclude?: FilterPattern;
|
|
9
10
|
include?: FilterPattern;
|
|
10
11
|
}
|
|
11
|
-
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
|
|
12
|
+
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
|
|
13
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,48 @@
|
|
|
1
1
|
import { createFilter } from "@rollup/pluginutils";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
import * as viteModule from "vite";
|
|
5
|
-
// @ts-ignore - check if transformWithOxc is available, i.e. rolldown-vite is installed and aliased
|
|
6
|
-
let useOxc = viteModule.transformWithOxc != null;
|
|
7
|
-
// @ts-ignore - assign transformer function
|
|
8
|
-
let transformWith = useOxc ? viteModule.transformWithOxc : transformWithEsbuild;
|
|
9
|
-
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
10
4
|
const filter = createFilter(include, exclude);
|
|
11
5
|
const postfixRE = /[?#].*$/s;
|
|
12
6
|
return {
|
|
13
7
|
name: "vite-plugin-svgr",
|
|
14
8
|
enforce: "pre", // to override `vite:asset`'s behavior
|
|
15
9
|
async load(id) {
|
|
16
|
-
if (filter(id)) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
if (!filter(id)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const filePath = id.replace(postfixRE, "");
|
|
14
|
+
const svgCode = await fs.promises.readFile(filePath, "utf8");
|
|
15
|
+
const { transform: svgrTransform } = await import("@svgr/core");
|
|
16
|
+
const { default: jsx } = await import("@svgr/plugin-jsx");
|
|
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, {
|
|
29
28
|
lang: "jsx",
|
|
30
|
-
...
|
|
31
|
-
} : {
|
|
32
|
-
loader: "jsx",
|
|
33
|
-
...esbuildOptions,
|
|
29
|
+
...oxcOptions,
|
|
34
30
|
});
|
|
35
31
|
return {
|
|
36
32
|
code: res.code,
|
|
37
33
|
map: null, // TODO:
|
|
38
34
|
};
|
|
39
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
|
+
};
|
|
40
46
|
},
|
|
41
47
|
};
|
|
42
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.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": [
|
|
@@ -34,15 +37,44 @@
|
|
|
34
37
|
"license": "MIT",
|
|
35
38
|
"devDependencies": {
|
|
36
39
|
"@types/node": "^24.3.0",
|
|
37
|
-
"
|
|
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
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@10.15.0+sha256.84c19e788d7d7ee248e4a6b7152f8ebba0f4fe7380a5f443ca17d76c030052d2"
|
|
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
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
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 };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.default = vitePluginSvgr;
|
|
40
|
-
const pluginutils_1 = require("@rollup/pluginutils");
|
|
41
|
-
const fs_1 = __importDefault(require("fs"));
|
|
42
|
-
const vite_1 = require("vite");
|
|
43
|
-
const viteModule = __importStar(require("vite"));
|
|
44
|
-
// @ts-ignore - check if transformWithOxc is available, i.e. rolldown-vite is installed and aliased
|
|
45
|
-
let useOxc = viteModule.transformWithOxc != null;
|
|
46
|
-
// @ts-ignore - assign transformer function
|
|
47
|
-
let transformWith = useOxc ? viteModule.transformWithOxc : vite_1.transformWithEsbuild;
|
|
48
|
-
function vitePluginSvgr({ svgrOptions, esbuildOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
49
|
-
const filter = (0, pluginutils_1.createFilter)(include, exclude);
|
|
50
|
-
const postfixRE = /[?#].*$/s;
|
|
51
|
-
return {
|
|
52
|
-
name: "vite-plugin-svgr",
|
|
53
|
-
enforce: "pre", // to override `vite:asset`'s behavior
|
|
54
|
-
async load(id) {
|
|
55
|
-
if (filter(id)) {
|
|
56
|
-
const { transform } = await Promise.resolve().then(() => __importStar(require("@svgr/core")));
|
|
57
|
-
const { default: jsx } = await Promise.resolve().then(() => __importStar(require("@svgr/plugin-jsx")));
|
|
58
|
-
const filePath = id.replace(postfixRE, "");
|
|
59
|
-
const svgCode = await fs_1.default.promises.readFile(filePath, "utf8");
|
|
60
|
-
const componentCode = await transform(svgCode, svgrOptions, {
|
|
61
|
-
filePath,
|
|
62
|
-
caller: {
|
|
63
|
-
defaultPlugins: [jsx],
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
const res = await transformWith(componentCode, id, useOxc ? {
|
|
67
|
-
// @ts-ignore - "lang" is required for transformWithOxc
|
|
68
|
-
lang: "jsx",
|
|
69
|
-
...esbuildOptions,
|
|
70
|
-
} : {
|
|
71
|
-
loader: "jsx",
|
|
72
|
-
...esbuildOptions,
|
|
73
|
-
});
|
|
74
|
-
return {
|
|
75
|
-
code: res.code,
|
|
76
|
-
map: null, // TODO:
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|