vite-plugin-svgr 3.0.0 → 3.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 ADDED
@@ -0,0 +1,60 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const pluginutils_1 = require("@rollup/pluginutils");
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const vite_1 = require("vite");
32
+ function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include = "**/*.svg", exclude, } = {}) {
33
+ const filter = (0, pluginutils_1.createFilter)(include, exclude);
34
+ return {
35
+ name: "vite-plugin-svgr",
36
+ async transform(code, id) {
37
+ if (filter(id)) {
38
+ const { transform } = await Promise.resolve().then(() => __importStar(require("@svgr/core")));
39
+ const { default: jsx } = await Promise.resolve().then(() => __importStar(require("@svgr/plugin-jsx")));
40
+ const svgCode = await fs_1.default.promises.readFile(id.replace(/\?.*$/, ""), "utf8");
41
+ const componentCode = await transform(svgCode, svgrOptions, {
42
+ filePath: id,
43
+ caller: {
44
+ previousExport: exportAsDefault ? null : code,
45
+ defaultPlugins: [jsx],
46
+ },
47
+ });
48
+ const res = await (0, vite_1.transformWithEsbuild)(componentCode, id, {
49
+ loader: "jsx",
50
+ ...esbuildOptions,
51
+ });
52
+ return {
53
+ code: res.code,
54
+ map: null, // TODO:
55
+ };
56
+ }
57
+ },
58
+ };
59
+ }
60
+ exports.default = viteSvgr;
package/dist/index.js CHANGED
@@ -8,11 +8,13 @@ export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions,
8
8
  async transform(code, id) {
9
9
  if (filter(id)) {
10
10
  const { transform } = await import("@svgr/core");
11
+ const { default: jsx } = await import("@svgr/plugin-jsx");
11
12
  const svgCode = await fs.promises.readFile(id.replace(/\?.*$/, ""), "utf8");
12
13
  const componentCode = await transform(svgCode, svgrOptions, {
13
14
  filePath: id,
14
15
  caller: {
15
16
  previousExport: exportAsDefault ? null : code,
17
+ defaultPlugins: [jsx],
16
18
  },
17
19
  });
18
20
  const res = await transformWithEsbuild(componentCode, id, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-svgr",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Vite plugin to transform SVGs into React components",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
12
13
  },
13
14
  "./client": {
14
15
  "types": "./client.d.ts"
@@ -16,7 +17,7 @@
16
17
  },
17
18
  "scripts": {
18
19
  "dev": "tsc --watch",
19
- "build": "tsc",
20
+ "build": "tsc --module commonjs && mv dist/index.js dist/index.cjs && tsc",
20
21
  "prepare": "npm run build"
21
22
  },
22
23
  "repository": "pd4d10/vite-plugin-svgr",
@@ -40,7 +41,8 @@
40
41
  },
41
42
  "dependencies": {
42
43
  "@rollup/pluginutils": "^5.0.2",
43
- "@svgr/core": "^7.0.0"
44
+ "@svgr/core": "^7.0.0",
45
+ "@svgr/plugin-jsx": "^7.0.0"
44
46
  },
45
47
  "packageManager": "pnpm@8.4.0"
46
48
  }