vite-plugin-svgr 0.4.0 → 0.5.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/lib/index.d.ts +2 -3
- package/lib/index.js +13 -11
- package/package.json +8 -14
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export = _default;
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
export default function svgrPlugin(): Plugin;
|
package/lib/index.js
CHANGED
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
6
|
const fs_1 = __importDefault(require("fs"));
|
|
6
|
-
|
|
7
|
+
const vite_1 = require("vite");
|
|
8
|
+
function svgrPlugin() {
|
|
7
9
|
// TODO: options
|
|
8
10
|
return {
|
|
9
11
|
name: 'vite:svgr',
|
|
10
12
|
async transform(code, id) {
|
|
11
|
-
if (id.endsWith('.svg')) {
|
|
13
|
+
if (id.endsWith('.svg') && !id.includes('node_modules')) {
|
|
12
14
|
const svgr = require('@svgr/core').default;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
15
|
+
const svgCode = await fs_1.default.promises.readFile(id, 'utf8');
|
|
16
|
+
const componentCode = await svgr(svgCode, {}, { componentName: 'ReactComponent' });
|
|
17
|
+
code =
|
|
18
|
+
code +
|
|
19
|
+
'\n' +
|
|
20
|
+
componentCode.replace('export default ReactComponent', 'export { ReactComponent }');
|
|
21
|
+
const res = await (0, vite_1.transformWithEsbuild)(code, id, { loader: 'jsx' });
|
|
21
22
|
return {
|
|
22
23
|
code: res.code,
|
|
23
24
|
map: null, // TODO:
|
|
@@ -25,4 +26,5 @@ module.exports = function svgrPlugin() {
|
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
};
|
|
28
|
-
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = svgrPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-svgr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Vite plugin to transform SVGs into React components",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,32 +8,26 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublish": "npm run build"
|
|
10
10
|
},
|
|
11
|
-
"repository":
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/pd4d10/vite-plugin-svgr.git"
|
|
14
|
-
},
|
|
11
|
+
"repository": "pd4d10/vite-plugin-svgr",
|
|
15
12
|
"files": [
|
|
16
13
|
"lib",
|
|
17
14
|
"client.d.ts"
|
|
18
15
|
],
|
|
19
16
|
"keywords": [
|
|
20
|
-
"vite"
|
|
17
|
+
"vite",
|
|
18
|
+
"vite-plugin"
|
|
21
19
|
],
|
|
22
20
|
"author": "Rongjian Zhang",
|
|
23
21
|
"license": "MIT",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://github.com/pd4d10/vite-plugin-svgr/issues"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://github.com/pd4d10/vite-plugin-svgr#readme",
|
|
28
22
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"typescript": "^4.
|
|
31
|
-
"vite": "^2.
|
|
23
|
+
"@types/node": "^16.11.6",
|
|
24
|
+
"typescript": "^4.4.4",
|
|
25
|
+
"vite": "^2.6.13"
|
|
32
26
|
},
|
|
33
27
|
"peerDependencies": {
|
|
34
28
|
"vite": "^2.0.0"
|
|
35
29
|
},
|
|
36
30
|
"dependencies": {
|
|
37
|
-
"@svgr/core": "^
|
|
31
|
+
"@svgr/core": "^6.0.0-alpha.2"
|
|
38
32
|
}
|
|
39
33
|
}
|