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 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 'vite-plugin-svgr'
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 './logo.svg'
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 overrides the default behavior of Vite.
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: '**/*.svg',
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 '*.svg' {
5
- import * as React from 'react'
4
+ declare module "*.svg" {
5
+ import * as React from "react";
6
6
 
7
7
  export const ReactComponent: React.FunctionComponent<
8
- React.ComponentProps<'svg'> & { title?: string }
9
- >
8
+ React.ComponentProps<"svg"> & { title?: string }
9
+ >;
10
10
  }
package/dist/index.d.ts CHANGED
@@ -1,23 +1,18 @@
1
- import type { Config } from '@svgr/core';
2
- import { FilterPattern } from '@rollup/pluginutils';
3
- import type { Plugin as Plugin_2 } from 'vite';
4
- import { transformWithEsbuild } from 'vite';
5
-
6
- declare function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include, exclude, }?: ViteSvgrOptions): Plugin_2;
7
- export default viteSvgr;
8
-
9
- export declare interface ViteSvgrOptions {
10
- /**
11
- * Export React component as default. Notice that it will overrides
12
- * the default behavior of Vite, which exports the URL as default
13
- *
14
- * @default false
15
- */
16
- exportAsDefault?: boolean;
17
- svgrOptions?: Config;
18
- esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
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
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
- mod
19
- ));
20
- const pluginutils = require("@rollup/pluginutils");
21
- const fs = require("fs");
22
- const vite = require("vite");
23
- function viteSvgr({
24
- exportAsDefault,
25
- svgrOptions,
26
- esbuildOptions,
27
- include = "**/*.svg",
28
- exclude
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": "2.3.0",
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.mjs",
12
- "require": "./dist/index.js"
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./client": {
14
+ "types": "./client.d.ts"
13
15
  }
14
16
  },
15
17
  "scripts": {
16
- "dev": "tsdv watch",
17
- "build": "tsdv 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.11.12",
33
- "tsdv": "^0.8.0",
34
- "typescript": "^4.9.4",
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": "^6.5.1"
43
+ "@svgr/core": "^7.0.0"
43
44
  },
44
- "packageManager": "pnpm@7.14.2"
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
- };