vite-plugin-svgr 4.5.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 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
@@ -38,44 +38,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.default = vitePluginSvgr;
40
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, } = {}) {
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, } = {}) {
49
45
  const filter = (0, pluginutils_1.createFilter)(include, exclude);
50
46
  const postfixRE = /[?#].*$/s;
51
47
  return {
52
48
  name: "vite-plugin-svgr",
53
49
  enforce: "pre", // to override `vite:asset`'s behavior
54
50
  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
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, {
68
67
  lang: "jsx",
69
- ...esbuildOptions,
70
- } : {
71
- loader: "jsx",
72
- ...esbuildOptions,
68
+ ...oxcOptions,
73
69
  });
74
70
  return {
75
71
  code: res.code,
76
72
  map: null, // TODO:
77
73
  };
78
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
+ };
79
85
  },
80
86
  };
81
87
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { FilterPattern } from "@rollup/pluginutils";
2
- import type { Config } from "@svgr/core";
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?: Parameters<typeof transformWithEsbuild>[2];
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,42 +1,48 @@
1
1
  import { createFilter } from "@rollup/pluginutils";
2
- import fs from "fs";
3
- import { transformWithEsbuild } from "vite";
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 { 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, } = {}) {
10
6
  const filter = createFilter(include, exclude);
11
7
  const postfixRE = /[?#].*$/s;
12
8
  return {
13
9
  name: "vite-plugin-svgr",
14
10
  enforce: "pre", // to override `vite:asset`'s behavior
15
11
  async load(id) {
16
- if (filter(id)) {
17
- const { transform } = await import("@svgr/core");
18
- const { default: jsx } = await import("@svgr/plugin-jsx");
19
- const filePath = id.replace(postfixRE, "");
20
- const svgCode = await fs.promises.readFile(filePath, "utf8");
21
- const componentCode = await transform(svgCode, svgrOptions, {
22
- filePath,
23
- caller: {
24
- defaultPlugins: [jsx],
25
- },
26
- });
27
- const res = await transformWith(componentCode, id, useOxc ? {
28
- // @ts-ignore - "lang" is required for transformWithOxc
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, {
29
28
  lang: "jsx",
30
- ...esbuildOptions,
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": "4.5.0",
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 --module commonjs && mv dist/index.js dist/index.cjs && 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
- "typescript": "^5.9.2"
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": ">=2.6.0"
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
  }