vite-plugin-svgr 0.5.0 → 0.5.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/lib/index.js +25 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
23
|
};
|
|
@@ -10,15 +29,13 @@ function svgrPlugin() {
|
|
|
10
29
|
return {
|
|
11
30
|
name: 'vite:svgr',
|
|
12
31
|
async transform(code, id) {
|
|
13
|
-
if (id.endsWith('.svg')
|
|
14
|
-
|
|
32
|
+
if (id.endsWith('.svg')) {
|
|
33
|
+
// TODO: exclude node_modules as an option
|
|
34
|
+
const { default: convert } = await Promise.resolve().then(() => __importStar(require('@svgr/core')));
|
|
15
35
|
const svgCode = await fs_1.default.promises.readFile(id, 'utf8');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
'\n' +
|
|
20
|
-
componentCode.replace('export default ReactComponent', 'export { ReactComponent }');
|
|
21
|
-
const res = await (0, vite_1.transformWithEsbuild)(code, id, { loader: 'jsx' });
|
|
36
|
+
let componentCode = await convert(svgCode, {}, { componentName: 'ReactComponent' });
|
|
37
|
+
componentCode = componentCode.replace('export default ReactComponent', 'export { ReactComponent }');
|
|
38
|
+
const res = await (0, vite_1.transformWithEsbuild)(componentCode + '\n' + code, id, { loader: 'jsx' });
|
|
22
39
|
return {
|
|
23
40
|
code: res.code,
|
|
24
41
|
map: null, // TODO:
|