vite-plugin-svgr 4.0.0 → 4.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 +12 -0
- package/dist/index.cjs +2 -1
- package/dist/index.js +2 -1
- package/dist/index.mjs +38 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
Vite plugin to transform SVGs into React components. Uses [svgr](https://github.com/gregberge/svgr) under the hood.
|
|
6
6
|
|
|
7
|
+
## Installation
|
|
8
|
+
```sh
|
|
9
|
+
# npm
|
|
10
|
+
npm install --save-dev vite-plugin-svgr
|
|
11
|
+
|
|
12
|
+
# yarn
|
|
13
|
+
yarn add -D vite-plugin-svgr
|
|
14
|
+
|
|
15
|
+
# pnpm
|
|
16
|
+
pnpm add -D vite-plugin-svgr
|
|
17
|
+
```
|
|
18
|
+
|
|
7
19
|
## Usage
|
|
8
20
|
|
|
9
21
|
```js
|
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,8 @@ function vitePluginSvgr({ svgrOptions, esbuildOptions, include = "**/*.svg?react
|
|
|
34
34
|
const postfixRE = /[?#].*$/s;
|
|
35
35
|
return {
|
|
36
36
|
name: "vite-plugin-svgr",
|
|
37
|
-
|
|
37
|
+
enforce: "pre",
|
|
38
|
+
async load(id) {
|
|
38
39
|
if (filter(id)) {
|
|
39
40
|
const { transform } = await Promise.resolve().then(() => __importStar(require("@svgr/core")));
|
|
40
41
|
const { default: jsx } = await Promise.resolve().then(() => __importStar(require("@svgr/plugin-jsx")));
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ export default function vitePluginSvgr({ svgrOptions, esbuildOptions, include =
|
|
|
6
6
|
const postfixRE = /[?#].*$/s;
|
|
7
7
|
return {
|
|
8
8
|
name: "vite-plugin-svgr",
|
|
9
|
-
|
|
9
|
+
enforce: "pre",
|
|
10
|
+
async load(id) {
|
|
10
11
|
if (filter(id)) {
|
|
11
12
|
const { transform } = await import("@svgr/core");
|
|
12
13
|
const { default: jsx } = await import("@svgr/plugin-jsx");
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { transformWithEsbuild } from "vite";
|
|
3
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
4
|
+
function viteSvgr({
|
|
5
|
+
exportAsDefault,
|
|
6
|
+
svgrOptions,
|
|
7
|
+
esbuildOptions,
|
|
8
|
+
include = "**/*.svg",
|
|
9
|
+
exclude
|
|
10
|
+
} = {}) {
|
|
11
|
+
const filter = createFilter(include, exclude);
|
|
12
|
+
return {
|
|
13
|
+
name: "vite-plugin-svgr",
|
|
14
|
+
async transform(code, id) {
|
|
15
|
+
if (filter(id)) {
|
|
16
|
+
const { transform } = await import("@svgr/core");
|
|
17
|
+
const svgCode = await fs.promises.readFile(id, "utf8");
|
|
18
|
+
const componentCode = await transform(svgCode, svgrOptions, {
|
|
19
|
+
filePath: id,
|
|
20
|
+
caller: {
|
|
21
|
+
previousExport: exportAsDefault ? null : code
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
25
|
+
loader: "jsx",
|
|
26
|
+
...esbuildOptions
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
code: res.code,
|
|
30
|
+
map: null
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
viteSvgr as default
|
|
38
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "Rongjian Zhang",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^20.
|
|
35
|
+
"@types/node": "^20.7.2",
|
|
36
36
|
"typescript": "^5.2.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|