vite-plugin-svgr 5.0.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/dist/index.d.ts +4 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/index.cjs +0 -87
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FilterPattern } from "@rollup/pluginutils";
|
|
2
|
-
import {
|
|
3
|
-
import type { EsbuildTransformOptions, Plugin,
|
|
2
|
+
import type { Config } from "@svgr/core";
|
|
3
|
+
import type { EsbuildTransformOptions, Plugin, transformWithOxc } from "vite";
|
|
4
|
+
type OxcTransformOptions = NonNullable<Parameters<typeof transformWithOxc>[2]>;
|
|
4
5
|
export interface VitePluginSvgrOptions {
|
|
5
6
|
svgrOptions?: Config;
|
|
6
7
|
esbuildOptions?: EsbuildTransformOptions;
|
|
@@ -9,3 +10,4 @@ export interface VitePluginSvgrOptions {
|
|
|
9
10
|
include?: FilterPattern;
|
|
10
11
|
}
|
|
11
12
|
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
|
|
13
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
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
3
|
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
6
4
|
const filter = createFilter(include, exclude);
|
|
@@ -14,6 +12,8 @@ export default function vitePluginSvgr({ svgrOptions, esbuildOptions, oxcOptions
|
|
|
14
12
|
}
|
|
15
13
|
const filePath = id.replace(postfixRE, "");
|
|
16
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
17
|
const componentCode = await svgrTransform(svgCode, svgrOptions, {
|
|
18
18
|
filePath,
|
|
19
19
|
caller: {
|
package/package.json
CHANGED
package/dist/index.cjs
DELETED
|
@@ -1,87 +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 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
|
-
};
|
|
87
|
-
}
|