vite-plugin-svgr 0.6.0 → 1.1.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 CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { Config } from '@svgr/core';
2
+ import { transformWithEsbuild } from 'vite';
2
3
  import type { Plugin } from 'vite';
3
4
  declare type Options = {
4
5
  svgrOptions?: Config;
6
+ esbuildOptions?: Parameters<typeof transformWithEsbuild>[2];
5
7
  };
6
- declare const _default: (options?: Options) => Plugin;
8
+ declare const _default: ({ svgrOptions, esbuildOptions, }?: Options) => Plugin;
7
9
  export = _default;
package/lib/index.js CHANGED
@@ -23,8 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  };
24
24
  const fs_1 = __importDefault(require("fs"));
25
25
  const vite_1 = require("vite");
26
- module.exports = function svgrPlugin(options = {}) {
27
- const { svgrOptions = {} } = options;
26
+ module.exports = function svgrPlugin({ svgrOptions, esbuildOptions, } = {}) {
28
27
  return {
29
28
  name: 'vite:svgr',
30
29
  async transform(code, id) {
@@ -33,10 +32,11 @@ module.exports = function svgrPlugin(options = {}) {
33
32
  const svgCode = await fs_1.default.promises.readFile(id, 'utf8');
34
33
  const componentCode = await convert(svgCode, svgrOptions, {
35
34
  componentName: 'ReactComponent',
35
+ filePath: id,
36
36
  }).then((res) => {
37
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
+ const res = await (0, vite_1.transformWithEsbuild)(componentCode + '\n' + code, id, Object.assign({ loader: 'jsx' }, esbuildOptions));
40
40
  return {
41
41
  code: res.code,
42
42
  map: null, // TODO:
package/package.json CHANGED
@@ -1,13 +1,8 @@
1
1
  {
2
2
  "name": "vite-plugin-svgr",
3
- "version": "0.6.0",
3
+ "version": "1.1.0",
4
4
  "description": "Vite plugin to transform SVGs into React components",
5
5
  "main": "lib/index.js",
6
- "scripts": {
7
- "dev": "tsc --watch",
8
- "build": "tsc",
9
- "prepublish": "npm run build"
10
- },
11
6
  "repository": "pd4d10/vite-plugin-svgr",
12
7
  "files": [
13
8
  "lib",
@@ -20,14 +15,19 @@
20
15
  "author": "Rongjian Zhang",
21
16
  "license": "MIT",
22
17
  "devDependencies": {
23
- "@types/node": "^16.11.6",
24
- "typescript": "^4.4.4",
25
- "vite": "^2.6.13"
18
+ "@types/node": "^17.0.8",
19
+ "typescript": "^4.5.4",
20
+ "vite": "^2.7.10"
26
21
  },
27
22
  "peerDependencies": {
28
23
  "vite": "^2.6.0"
29
24
  },
30
25
  "dependencies": {
31
- "@svgr/core": "^6.0.0-alpha.3"
32
- }
33
- }
26
+ "@svgr/core": "^6.2.0"
27
+ },
28
+ "scripts": {
29
+ "dev": "tsc --watch",
30
+ "build": "tsc"
31
+ },
32
+ "readme": "# vite-plugin-svgr\n\n[![npm](https://img.shields.io/npm/v/vite-plugin-svgr.svg)](https://www.npmjs.com/package/vite-plugin-svgr)\n\nVite plugin to transform SVGs into React components. Uses [svgr](https://github.com/gregberge/svgr) under the hood.\n\n## Usage\n\n```js\n// vite.config.js\nimport svgrPlugin from 'vite-plugin-svgr'\n\nexport default {\n // ...\n plugins: [\n svgrPlugin({\n svgrOptions: {\n icon: true,\n // ...svgr options (https://react-svgr.com/docs/options/)\n },\n }),\n ],\n}\n```\n\nThen SVG files can be imported as React components, just like [create-react-app](https://create-react-app.dev/docs/adding-images-fonts-and-files#adding-svgs) does:\n\n```js\nimport { ReactComponent as Logo } from './logo.svg'\n```\n\nIf you are using TypeScript, `vite-plugin-svgr/client` can be added to `tsconfig.json`:\n\n```json\n{\n // ...\n \"compilerOptions\": {\n // ...\n \"types\": [\"vite-plugin-svgr/client\"]\n }\n}\n```\n\n## License\n\nMIT\n"
33
+ }