vite-plugin-svgr 2.1.0 → 2.2.1

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
@@ -45,6 +45,12 @@ svgr({
45
45
  esbuildOptions: {
46
46
  // ...
47
47
  },
48
+
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',
51
+
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: '',
48
54
  })
49
55
  ```
50
56
 
package/dist/index.d.ts CHANGED
@@ -1,15 +1,23 @@
1
- import type { Config } from '@svgr/core';
2
- import { transformWithEsbuild } from 'vite';
3
- import type { Plugin } from 'vite';
4
- export interface ViteSvgrOptions {
5
- /**
6
- * Export React component as default. Notice that it will overrides
7
- * the default behavior of Vite, which exports the URL as default
8
- *
9
- * @default false
10
- */
11
- exportAsDefault?: boolean;
12
- svgrOptions?: Config;
13
- esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
14
- }
15
- export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, }?: ViteSvgrOptions): Plugin;
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 { }
package/dist/index.js CHANGED
@@ -1,53 +1,57 @@
1
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]; } };
2
+ const fs = require("fs");
3
+ const vite = require("vite");
4
+ const pluginutils = require("@rollup/pluginutils");
5
+ const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
6
+ function _interopNamespace(e) {
7
+ if (e && e.__esModule)
8
+ return e;
9
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
+ if (e) {
11
+ for (const k in e) {
12
+ if (k !== "default") {
13
+ const d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: () => e[k]
17
+ });
18
+ }
7
19
  }
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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const fs_1 = __importDefault(require("fs"));
30
- const vite_1 = require("vite");
31
- function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, } = {}) {
32
- return {
33
- name: 'vite-plugin-svgr',
34
- async transform(code, id) {
35
- if (id.endsWith('.svg')) {
36
- const { transform } = await Promise.resolve().then(() => __importStar(require('@svgr/core')));
37
- const svgCode = await fs_1.default.promises.readFile(id, 'utf8');
38
- const componentCode = await transform(svgCode, svgrOptions, {
39
- filePath: id,
40
- caller: {
41
- previousExport: exportAsDefault ? null : code,
42
- },
43
- });
44
- const res = await (0, vite_1.transformWithEsbuild)(componentCode, id, Object.assign({ loader: 'jsx' }, esbuildOptions));
45
- return {
46
- code: res.code,
47
- map: null, // TODO:
48
- };
49
- }
50
- },
51
- };
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
52
23
  }
53
- exports.default = viteSvgr;
24
+ const fs__default = /* @__PURE__ */ _interopDefaultLegacy(fs);
25
+ function viteSvgr({
26
+ exportAsDefault,
27
+ svgrOptions,
28
+ esbuildOptions,
29
+ include = "**/*.svg",
30
+ exclude
31
+ } = {}) {
32
+ const filter = pluginutils.createFilter(include, exclude);
33
+ return {
34
+ name: "vite-plugin-svgr",
35
+ async transform(code, id) {
36
+ if (filter(id)) {
37
+ const { transform } = await Promise.resolve().then(() => /* @__PURE__ */ _interopNamespace(require("@svgr/core")));
38
+ const svgCode = await fs__default.default.promises.readFile(id, "utf8");
39
+ const componentCode = await transform(svgCode, svgrOptions, {
40
+ filePath: id,
41
+ caller: {
42
+ previousExport: exportAsDefault ? null : code
43
+ }
44
+ });
45
+ const res = await vite.transformWithEsbuild(componentCode, id, {
46
+ loader: "jsx",
47
+ ...esbuildOptions
48
+ });
49
+ return {
50
+ code: res.code,
51
+ map: null
52
+ };
53
+ }
54
+ }
55
+ };
56
+ }
57
+ module.exports = viteSvgr;
package/dist/index.mjs CHANGED
@@ -1,24 +1,38 @@
1
- import fs from 'fs';
2
- import { transformWithEsbuild } from 'vite';
3
- export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, } = {}) {
4
- return {
5
- name: 'vite-plugin-svgr',
6
- async transform(code, id) {
7
- if (id.endsWith('.svg')) {
8
- const { transform } = await import('@svgr/core');
9
- const svgCode = await fs.promises.readFile(id, 'utf8');
10
- const componentCode = await transform(svgCode, svgrOptions, {
11
- filePath: id,
12
- caller: {
13
- previousExport: exportAsDefault ? null : code,
14
- },
15
- });
16
- const res = await transformWithEsbuild(componentCode, id, Object.assign({ loader: 'jsx' }, esbuildOptions));
17
- return {
18
- code: res.code,
19
- map: null, // TODO:
20
- };
21
- }
22
- },
23
- };
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
+ };
24
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": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "description": "Vite plugin to transform SVGs into React components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -13,9 +13,9 @@
13
13
  }
14
14
  },
15
15
  "scripts": {
16
- "dev": "tsc --watch",
17
- "build": "tsc && tsc --module esnext --outDir temp && mv temp/index.js dist/index.mjs && rm -rf temp",
18
- "prepare": "rm -rf lib && npm run build"
16
+ "dev": "tsdv watch",
17
+ "build": "tsdv build",
18
+ "prepare": "npm run build"
19
19
  },
20
20
  "repository": "pd4d10/vite-plugin-svgr",
21
21
  "files": [
@@ -29,14 +29,16 @@
29
29
  "author": "Rongjian Zhang",
30
30
  "license": "MIT",
31
31
  "devDependencies": {
32
- "@types/node": "^17.0.30",
33
- "typescript": "^4.6.4",
34
- "vite": "^2.9.6"
32
+ "@types/node": "^18.0.6",
33
+ "tsdv": "^0.6.0",
34
+ "typescript": "^4.7.4",
35
+ "vite": "^3.0.2"
35
36
  },
36
37
  "peerDependencies": {
37
- "vite": "^2.6.0"
38
+ "vite": "^2.6.0 || 3"
38
39
  },
39
40
  "dependencies": {
40
- "@svgr/core": "^6.2.1"
41
+ "@rollup/pluginutils": "^4.2.1",
42
+ "@svgr/core": "^6.3.1"
41
43
  }
42
44
  }