vite-plugin-svgr 3.3.0 → 4.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 +4 -8
- package/client.d.ts +4 -2
- package/dist/index.cjs +2 -3
- package/dist/index.d.ts +2 -9
- package/dist/index.js +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,10 +16,10 @@ export default {
|
|
|
16
16
|
};
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Then SVG files can be imported as React components
|
|
19
|
+
Then SVG files can be imported as React components:
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
import
|
|
22
|
+
import Logo from "./logo.svg?react";
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
If you are using TypeScript, there is also a declaration helper for better type inference:
|
|
@@ -32,10 +32,6 @@ If you are using TypeScript, there is also a declaration helper for better type
|
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
svgr({
|
|
35
|
-
// Set it to `true` to export React component as default.
|
|
36
|
-
// Notice that it will override the default behavior of Vite.
|
|
37
|
-
exportAsDefault: false,
|
|
38
|
-
|
|
39
35
|
// svgr options: https://react-svgr.com/docs/options/
|
|
40
36
|
svgrOptions: {
|
|
41
37
|
// ...
|
|
@@ -46,8 +42,8 @@ svgr({
|
|
|
46
42
|
// ...
|
|
47
43
|
},
|
|
48
44
|
|
|
49
|
-
//
|
|
50
|
-
include: "**/*.svg",
|
|
45
|
+
// 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.
|
|
46
|
+
include: "**/*.svg?react",
|
|
51
47
|
|
|
52
48
|
// 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
49
|
exclude: "",
|
package/client.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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 "*.svg" {
|
|
4
|
+
declare module "*.svg?react" {
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const ReactComponent: React.FunctionComponent<
|
|
8
8
|
React.ComponentProps<"svg"> & { title?: string }
|
|
9
9
|
>;
|
|
10
|
+
|
|
11
|
+
export default ReactComponent;
|
|
10
12
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const pluginutils_1 = require("@rollup/pluginutils");
|
|
30
30
|
const fs_1 = __importDefault(require("fs"));
|
|
31
31
|
const vite_1 = require("vite");
|
|
32
|
-
function
|
|
32
|
+
function vitePluginSvgr({ svgrOptions, esbuildOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
33
33
|
const filter = (0, pluginutils_1.createFilter)(include, exclude);
|
|
34
34
|
const postfixRE = /[?#].*$/s;
|
|
35
35
|
return {
|
|
@@ -43,7 +43,6 @@ function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include = "**/
|
|
|
43
43
|
const componentCode = await transform(svgCode, svgrOptions, {
|
|
44
44
|
filePath,
|
|
45
45
|
caller: {
|
|
46
|
-
previousExport: exportAsDefault ? null : code,
|
|
47
46
|
defaultPlugins: [jsx],
|
|
48
47
|
},
|
|
49
48
|
});
|
|
@@ -59,4 +58,4 @@ function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include = "**/
|
|
|
59
58
|
},
|
|
60
59
|
};
|
|
61
60
|
}
|
|
62
|
-
exports.default =
|
|
61
|
+
exports.default = vitePluginSvgr;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,17 +2,10 @@ import { FilterPattern } from "@rollup/pluginutils";
|
|
|
2
2
|
import type { Config } from "@svgr/core";
|
|
3
3
|
import type { Plugin } from "vite";
|
|
4
4
|
import { transformWithEsbuild } from "vite";
|
|
5
|
-
export interface
|
|
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;
|
|
5
|
+
export interface VitePluginSvgrOptions {
|
|
13
6
|
svgrOptions?: Config;
|
|
14
7
|
esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
|
|
15
8
|
exclude?: FilterPattern;
|
|
16
9
|
include?: FilterPattern;
|
|
17
10
|
}
|
|
18
|
-
export default function
|
|
11
|
+
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, include, exclude, }?: VitePluginSvgrOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createFilter } from "@rollup/pluginutils";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { transformWithEsbuild } from "vite";
|
|
4
|
-
export default function
|
|
4
|
+
export default function vitePluginSvgr({ svgrOptions, esbuildOptions, include = "**/*.svg?react", exclude, } = {}) {
|
|
5
5
|
const filter = createFilter(include, exclude);
|
|
6
6
|
const postfixRE = /[?#].*$/s;
|
|
7
7
|
return {
|
|
@@ -15,7 +15,6 @@ export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions,
|
|
|
15
15
|
const componentCode = await transform(svgCode, svgrOptions, {
|
|
16
16
|
filePath,
|
|
17
17
|
caller: {
|
|
18
|
-
previousExport: exportAsDefault ? null : code,
|
|
19
18
|
defaultPlugins: [jsx],
|
|
20
19
|
},
|
|
21
20
|
});
|