vite-plugin-svgr 0.5.1 → 0.6.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 +8 -1
- package/lib/index.d.ts +7 -2
- package/lib/index.js +9 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,7 +12,14 @@ import svgrPlugin from 'vite-plugin-svgr'
|
|
|
12
12
|
|
|
13
13
|
export default {
|
|
14
14
|
// ...
|
|
15
|
-
plugins: [
|
|
15
|
+
plugins: [
|
|
16
|
+
svgrPlugin({
|
|
17
|
+
svgrOptions: {
|
|
18
|
+
icon: true,
|
|
19
|
+
// ...svgr options (https://react-svgr.com/docs/options/)
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
16
23
|
}
|
|
17
24
|
```
|
|
18
25
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { Config } from '@svgr/core';
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
|
+
declare type Options = {
|
|
4
|
+
svgrOptions?: Config;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: (options?: Options) => Plugin;
|
|
7
|
+
export = _default;
|
package/lib/index.js
CHANGED
|
@@ -21,20 +21,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
24
|
const fs_1 = __importDefault(require("fs"));
|
|
26
25
|
const vite_1 = require("vite");
|
|
27
|
-
function svgrPlugin() {
|
|
28
|
-
|
|
26
|
+
module.exports = function svgrPlugin(options = {}) {
|
|
27
|
+
const { svgrOptions = {} } = options;
|
|
29
28
|
return {
|
|
30
29
|
name: 'vite:svgr',
|
|
31
30
|
async transform(code, id) {
|
|
32
31
|
if (id.endsWith('.svg')) {
|
|
33
|
-
|
|
34
|
-
const { default: convert } = await Promise.resolve().then(() => __importStar(require('@svgr/core')));
|
|
32
|
+
const { transform: convert } = await Promise.resolve().then(() => __importStar(require('@svgr/core')));
|
|
35
33
|
const svgCode = await fs_1.default.promises.readFile(id, 'utf8');
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const componentCode = await convert(svgCode, svgrOptions, {
|
|
35
|
+
componentName: 'ReactComponent',
|
|
36
|
+
}).then((res) => {
|
|
37
|
+
return res.replace('export default ReactComponent', `export { ReactComponent }`);
|
|
38
|
+
});
|
|
38
39
|
const res = await (0, vite_1.transformWithEsbuild)(componentCode + '\n' + code, id, { loader: 'jsx' });
|
|
39
40
|
return {
|
|
40
41
|
code: res.code,
|
|
@@ -43,5 +44,4 @@ function svgrPlugin() {
|
|
|
43
44
|
}
|
|
44
45
|
},
|
|
45
46
|
};
|
|
46
|
-
}
|
|
47
|
-
exports.default = svgrPlugin;
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"vite": "^2.6.13"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"vite": "^2.
|
|
28
|
+
"vite": "^2.6.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@svgr/core": "^6.0.0-alpha.
|
|
31
|
+
"@svgr/core": "^6.0.0-alpha.3"
|
|
32
32
|
}
|
|
33
33
|
}
|