vite-plugin-svgr 2.3.0 → 3.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 +7 -7
- package/client.d.ts +4 -4
- package/dist/index.d.ts +18 -23
- package/dist/index.js +28 -57
- package/package.json +13 -12
- package/dist/index.mjs +0 -41
package/README.md
CHANGED
|
@@ -8,18 +8,18 @@ Vite plugin to transform SVGs into React components. Uses [svgr](https://github.
|
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
10
|
// vite.config.js
|
|
11
|
-
import svgr from
|
|
11
|
+
import svgr from "vite-plugin-svgr";
|
|
12
12
|
|
|
13
13
|
export default {
|
|
14
14
|
// ...
|
|
15
15
|
plugins: [svgr()],
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Then SVG files can be imported as React components, just like [create-react-app](https://create-react-app.dev/docs/adding-images-fonts-and-files#adding-svgs) does:
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
import { ReactComponent as Logo } from
|
|
22
|
+
import { ReactComponent as Logo } from "./logo.svg";
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
If you are using TypeScript, there is also a declaration helper for better type inference:
|
|
@@ -33,7 +33,7 @@ If you are using TypeScript, there is also a declaration helper for better type
|
|
|
33
33
|
```js
|
|
34
34
|
svgr({
|
|
35
35
|
// Set it to `true` to export React component as default.
|
|
36
|
-
// Notice that it will
|
|
36
|
+
// Notice that it will override the default behavior of Vite.
|
|
37
37
|
exportAsDefault: false,
|
|
38
38
|
|
|
39
39
|
// svgr options: https://react-svgr.com/docs/options/
|
|
@@ -47,11 +47,11 @@ svgr({
|
|
|
47
47
|
},
|
|
48
48
|
|
|
49
49
|
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should include. By default all svg files will be included.
|
|
50
|
-
include:
|
|
50
|
+
include: "**/*.svg",
|
|
51
51
|
|
|
52
52
|
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
|
|
53
|
-
exclude:
|
|
54
|
-
})
|
|
53
|
+
exclude: "",
|
|
54
|
+
});
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## License
|
package/client.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// https://github.com/facebook/create-react-app/blob/0ee4765c39f820e5f4820abf4bf2e47b3324da7f/packages/react-scripts/lib/react-app.d.ts#L47-L56
|
|
2
2
|
// https://github.com/pd4d10/vite-plugin-svgr/pull/56 for preact compatiblility
|
|
3
3
|
|
|
4
|
-
declare module
|
|
5
|
-
import * as React from
|
|
4
|
+
declare module "*.svg" {
|
|
5
|
+
import * as React from "react";
|
|
6
6
|
|
|
7
7
|
export const ReactComponent: React.FunctionComponent<
|
|
8
|
-
React.ComponentProps<
|
|
9
|
-
|
|
8
|
+
React.ComponentProps<"svg"> & { title?: string }
|
|
9
|
+
>;
|
|
10
10
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type { Plugin
|
|
4
|
-
import { transformWithEsbuild } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exclude?: FilterPattern;
|
|
20
|
-
include?: FilterPattern;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { }
|
|
1
|
+
import { FilterPattern } from "@rollup/pluginutils";
|
|
2
|
+
import type { Config } from "@svgr/core";
|
|
3
|
+
import type { Plugin } from "vite";
|
|
4
|
+
import { transformWithEsbuild } from "vite";
|
|
5
|
+
export interface ViteSvgrOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Export React component as default. Notice that it will overrides
|
|
8
|
+
* the default behavior of Vite, which exports the URL as default
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
exportAsDefault?: boolean;
|
|
13
|
+
svgrOptions?: Config;
|
|
14
|
+
esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
|
|
15
|
+
exclude?: FilterPattern;
|
|
16
|
+
include?: FilterPattern;
|
|
17
|
+
}
|
|
18
|
+
export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include, exclude, }?: ViteSvgrOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,58 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} = {}) {
|
|
30
|
-
const filter = pluginutils.createFilter(include, exclude);
|
|
31
|
-
return {
|
|
32
|
-
name: "vite-plugin-svgr",
|
|
33
|
-
async transform(code, id) {
|
|
34
|
-
if (filter(id)) {
|
|
35
|
-
const { transform } = await import("@svgr/core");
|
|
36
|
-
const svgCode = await fs.promises.readFile(
|
|
37
|
-
id.replace(/\?.*$/, ""),
|
|
38
|
-
"utf8"
|
|
39
|
-
);
|
|
40
|
-
const componentCode = await transform(svgCode, svgrOptions, {
|
|
41
|
-
filePath: id,
|
|
42
|
-
caller: {
|
|
43
|
-
previousExport: exportAsDefault ? null : code
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
const res = await vite.transformWithEsbuild(componentCode, id, {
|
|
47
|
-
loader: "jsx",
|
|
48
|
-
...esbuildOptions
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
code: res.code,
|
|
52
|
-
map: null
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
1
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { transformWithEsbuild } from "vite";
|
|
4
|
+
export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include = "**/*.svg", exclude, } = {}) {
|
|
5
|
+
const filter = createFilter(include, exclude);
|
|
6
|
+
return {
|
|
7
|
+
name: "vite-plugin-svgr",
|
|
8
|
+
async transform(code, id) {
|
|
9
|
+
if (filter(id)) {
|
|
10
|
+
const { transform } = await import("@svgr/core");
|
|
11
|
+
const svgCode = await fs.promises.readFile(id.replace(/\?.*$/, ""), "utf8");
|
|
12
|
+
const componentCode = await transform(svgCode, svgrOptions, {
|
|
13
|
+
filePath: id,
|
|
14
|
+
caller: {
|
|
15
|
+
previousExport: exportAsDefault ? null : code,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const res = await transformWithEsbuild(componentCode, id, {
|
|
19
|
+
loader: "jsx",
|
|
20
|
+
...esbuildOptions,
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
code: res.code,
|
|
24
|
+
map: null, // TODO:
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
57
29
|
}
|
|
58
|
-
module.exports = viteSvgr;
|
package/package.json
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.
|
|
12
|
-
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./client.d.ts"
|
|
13
15
|
}
|
|
14
16
|
},
|
|
15
17
|
"scripts": {
|
|
16
|
-
"dev": "
|
|
17
|
-
"build": "
|
|
18
|
+
"dev": "tsc --watch",
|
|
19
|
+
"build": "tsc",
|
|
18
20
|
"prepare": "npm run build"
|
|
19
21
|
},
|
|
20
22
|
"repository": "pd4d10/vite-plugin-svgr",
|
|
@@ -29,17 +31,16 @@
|
|
|
29
31
|
"author": "Rongjian Zhang",
|
|
30
32
|
"license": "MIT",
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^18.
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"vite": "^4.0.0"
|
|
34
|
+
"@types/node": "^18.16.0",
|
|
35
|
+
"typescript": "^5.0.4",
|
|
36
|
+
"vite": "^4.3.2"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"vite": "^2.6.0 || 3 || 4"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@rollup/pluginutils": "^5.0.2",
|
|
42
|
-
"@svgr/core": "^
|
|
43
|
+
"@svgr/core": "^7.0.0"
|
|
43
44
|
},
|
|
44
|
-
"packageManager": "pnpm@
|
|
45
|
+
"packageManager": "pnpm@8.4.0"
|
|
45
46
|
}
|
package/dist/index.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { transformWithEsbuild } from "vite";
|
|
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(
|
|
18
|
-
id.replace(/\?.*$/, ""),
|
|
19
|
-
"utf8"
|
|
20
|
-
);
|
|
21
|
-
const componentCode = await transform(svgCode, svgrOptions, {
|
|
22
|
-
filePath: id,
|
|
23
|
-
caller: {
|
|
24
|
-
previousExport: exportAsDefault ? null : code
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const res = await transformWithEsbuild(componentCode, id, {
|
|
28
|
-
loader: "jsx",
|
|
29
|
-
...esbuildOptions
|
|
30
|
-
});
|
|
31
|
-
return {
|
|
32
|
-
code: res.code,
|
|
33
|
-
map: null
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
viteSvgr as default
|
|
41
|
-
};
|