vite-plugin-svgr 2.1.1 → 2.2.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 +6 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/package.json +2 -1
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,6 +1,7 @@
|
|
|
1
1
|
import type { Config } from '@svgr/core';
|
|
2
2
|
import { transformWithEsbuild } from 'vite';
|
|
3
3
|
import type { Plugin } from 'vite';
|
|
4
|
+
import { FilterPattern } from '@rollup/pluginutils';
|
|
4
5
|
export interface ViteSvgrOptions {
|
|
5
6
|
/**
|
|
6
7
|
* Export React component as default. Notice that it will overrides
|
|
@@ -11,5 +12,7 @@ export interface ViteSvgrOptions {
|
|
|
11
12
|
exportAsDefault?: boolean;
|
|
12
13
|
svgrOptions?: Config;
|
|
13
14
|
esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
|
|
15
|
+
exclude?: FilterPattern;
|
|
16
|
+
include?: FilterPattern;
|
|
14
17
|
}
|
|
15
|
-
export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, }?: ViteSvgrOptions): Plugin;
|
|
18
|
+
export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include, exclude, }?: ViteSvgrOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -28,11 +28,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const fs_1 = __importDefault(require("fs"));
|
|
30
30
|
const vite_1 = require("vite");
|
|
31
|
-
|
|
31
|
+
const pluginutils_1 = require("@rollup/pluginutils");
|
|
32
|
+
function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include = '**/*.svg', exclude, } = {}) {
|
|
33
|
+
const filter = (0, pluginutils_1.createFilter)(include, exclude);
|
|
32
34
|
return {
|
|
33
35
|
name: 'vite-plugin-svgr',
|
|
34
36
|
async transform(code, id) {
|
|
35
|
-
if (id
|
|
37
|
+
if (filter(id)) {
|
|
36
38
|
const { transform } = await Promise.resolve().then(() => __importStar(require('@svgr/core')));
|
|
37
39
|
const svgCode = await fs_1.default.promises.readFile(id, 'utf8');
|
|
38
40
|
const componentCode = await transform(svgCode, svgrOptions, {
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { transformWithEsbuild } from 'vite';
|
|
3
|
-
|
|
3
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
4
|
+
export default function viteSvgr({ exportAsDefault, svgrOptions, esbuildOptions, include = '**/*.svg', exclude, } = {}) {
|
|
5
|
+
const filter = createFilter(include, exclude);
|
|
4
6
|
return {
|
|
5
7
|
name: 'vite-plugin-svgr',
|
|
6
8
|
async transform(code, id) {
|
|
7
|
-
if (id
|
|
9
|
+
if (filter(id)) {
|
|
8
10
|
const { transform } = await import('@svgr/core');
|
|
9
11
|
const svgCode = await fs.promises.readFile(id, 'utf8');
|
|
10
12
|
const componentCode = await transform(svgCode, svgrOptions, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"vite": "^2.6.0 || 3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@rollup/pluginutils": "^4.2.1",
|
|
40
41
|
"@svgr/core": "^6.2.1"
|
|
41
42
|
}
|
|
42
43
|
}
|