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 CHANGED
@@ -1,87 +1,67 @@
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 };
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
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = vitePluginSvgr;
40
- const pluginutils_1 = require("@rollup/pluginutils");
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, } = {}) {
45
- const filter = (0, pluginutils_1.createFilter)(include, exclude);
46
- const postfixRE = /[?#].*$/s;
47
- return {
48
- name: "vite-plugin-svgr",
49
- enforce: "pre", // to override `vite:asset`'s behavior
50
- async load(id) {
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,
69
- });
70
- return {
71
- code: res.code,
72
- map: null, // TODO:
73
- };
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
- };
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;
@@ -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 { type FilterPattern } from "@rollup/pluginutils";
2
- import { type Config } from "@svgr/core";
3
- import type { EsbuildTransformOptions, Plugin, TransformOptions as OxcTransformOptions } from "vite";
4
- export interface VitePluginSvgrOptions {
5
- svgrOptions?: Config;
6
- esbuildOptions?: EsbuildTransformOptions;
7
- oxcOptions?: OxcTransformOptions;
8
- exclude?: FilterPattern;
9
- include?: FilterPattern;
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
- export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
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
- export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude, } = {}) {
6
- const filter = createFilter(include, exclude);
7
- const postfixRE = /[?#].*$/s;
8
- return {
9
- name: "vite-plugin-svgr",
10
- enforce: "pre", // to override `vite:asset`'s behavior
11
- async load(id) {
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,
30
- });
31
- return {
32
- code: res.code,
33
- map: null, // TODO:
34
- };
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
- };
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.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "Vite plugin to transform SVGs into React components",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.cts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
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": "tsc --watch",
19
- "build": "tsc -p tsconfig.json",
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": "^24.3.0",
40
- "c8": "^10.1.3",
46
+ "@types/node": "^25.5.0",
47
+ "c8": "^11.0.0",
48
+ "tsdown": "^0.21.7",
41
49
  "tsx": "^4.21.0",
42
- "typescript": "^5.9.2",
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.2.0",
63
+ "@rollup/pluginutils": "^5.3.0",
56
64
  "@svgr/core": "^8.1.0",
57
65
  "@svgr/plugin-jsx": "^8.1.0"
58
66
  },