{"id":18116794,"url":"https://github.com/platypusrex/next-plugin-svgr","last_synced_at":"2025-04-05T21:06:07.209Z","repository":{"id":40288757,"uuid":"247187242","full_name":"platypusrex/next-plugin-svgr","owner":"platypusrex","description":"Next.js plugin for SVGR","archived":false,"fork":false,"pushed_at":"2025-03-21T17:38:38.000Z","size":806,"stargazers_count":38,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-29T20:06:28.255Z","etag":null,"topics":["nextjs","svgr","webpack"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/next-plugin-svgr","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/platypusrex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-14T00:49:54.000Z","updated_at":"2025-03-14T10:42:32.000Z","dependencies_parsed_at":"2023-02-10T13:00:19.103Z","dependency_job_id":"556ed3ff-cead-4bb1-a3bf-b0926afb4020","html_url":"https://github.com/platypusrex/next-plugin-svgr","commit_stats":{"total_commits":70,"total_committers":4,"mean_commits":17.5,"dds":0.3571428571428571,"last_synced_commit":"c94a10697749b27ee003bb042e6673341460a2d3"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnext-plugin-svgr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnext-plugin-svgr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnext-plugin-svgr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnext-plugin-svgr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/platypusrex","download_url":"https://codeload.github.com/platypusrex/next-plugin-svgr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399871,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs","svgr","webpack"],"created_at":"2024-11-01T04:14:50.348Z","updated_at":"2025-04-05T21:06:07.184Z","avatar_url":"https://github.com/platypusrex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js + SVGR\n[![npm package](https://img.shields.io/npm/v/next-plugin-svgr/latest.svg)](https://www.npmjs.com/package/next-plugin-svgr)\n[![Dependencies](https://img.shields.io/npm/dm/next-plugin-svgr)](https://www.npmjs.com/package/next-plugin-svgr)\n[![License](https://img.shields.io/npm/l/express.svg)](https://github.com/platypusrex/next-merge-props/blob/master/LICENSE)\n\nFlexible [Next.js](https://github.com/zeit/next.js) plugin for transforming svg's into react components using the svgr library\n\n### Installation\n\nnpm\n\n```\nnpm install --save next-plugin-svgr\n```\n\nor yarn\n\n```\nyarn add next-plugin-svgr\n```\n### Usage\n\nCreate a `next.config.js` in your project\n\n```js\n// next.config.js\nconst withSvgr = require('next-plugin-svgr');\n\nmodule.exports = withSvgr();\n```\n\nOptionally add Next.js configuration as a parameter\n\n```js\n// next.config.js\nconst withSvgr = require('next-plugin-svgr');\n\nmodule.exports = withSvgr({\n  webpack(config, options) {\n    return config;\n  },\n});\n```\n\nOr with [`next-compose-plugins`](https://github.com/cyrilwanner/next-compose-plugins) when composing multiple plugins\n\n```js\n// next.config.js\nconst withPlugins = require(\"next-compose-plugins\");\nconst withSvgr = require(\"next-plugin-svgr\");\n\nmodule.exports = withPlugins([\n  withSvgr\n  // your other plugins here\n]);\n```\n\nAnd now in your components you can use the svg as a component\n\n```js\nimport Icon from './icon.svg';\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    \u003cIcon /\u003e\n  \u003c/div\u003e\n);\n```\n\n### Options\n\n#### svgrOptions\n\nThe plugins supports all available options of svgr webpack loader.\nCheck out the [svgr documentation](https://react-svgr.com/docs/options/) for the full list of options.\n\nExample with options:\n\n```js\nmodule.exports = withSvgr({\n  svgrOptions: {\n    titleProp: true,\n    icon: true,\n    svgProps: {\n      height: 'auto',\n    },\n  },\n});\n```\n\nYou can optionally specify a project configuration file. SVGR uses \n[cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support,\nwhich means that any file type accepted by cosmicconfig is supported.\n\n* .svgrrc file, written in YAML or JSON, with optional extensions: .yaml/.yml/.json/.js.\n* A svgr.config.js file that exports an object.\n* A \"svgr\" key in your package.json file.\n\n**note:** The plugin will automatically detect your config file so you shouldn't have to include the `configFile`\nproperty in `svgrOptions`. The option to specify exists and can be accomplished following the example below.\n\n```js\n// .svgrrc.js\nmodule.exports = {\n  icon: true,\n  expandProps: false,\n};\n\n// next.config.js\nmodule.exports = withSvgr({\n  svgrOptions: {\n    configFile: path.resolve(__dirname, '.svgrrc.js'),\n  },\n});\n\n// or with next-compose-plugins\nmodule.exports = withPlugins([\n  withGraphql,\n  [withSvgr, {\n    svgrOptions: {\n      configFile: path.resolve(__dirname, '.svgrrc.js'),\n    },\n  }],\n]);\n```\n\n#### fileLoader\n\nIf you would like to use the svgr webpack loader with [file-loader](https://github.com/webpack-contrib/file-loader). \nAccepts a `boolean` or all available [options](https://github.com/webpack-contrib/file-loader#options) for file-loader.\n\nThe `fileLoader` option is `undefined` by default. If defined, it will apply the options below.\n\n**note:** If using `file-loader` and typescript remember to reference the svgr/file-loader types. See [below](#typescript).\n\nDefault options:\n\n```\n{\n  limit: 8192,\n  publicPath: `${assetPrefix ?? ''}/_next/${path}`,\n  outputPath: `${isServer ? '../' : ''}${path}`,\n  name: '[path][name].[hash].[ext]',\n}\n```\n\n```js\nmodule.exports = withSvgr({\n  fileLoader: true,\n  svgrOptions: {\n    ...options\n  },\n});\n```\n\n```js\nmodule.exports = withSvgr({\n  fileLoader: {\n    limit: 16384,\n    name(resourcePath, resourceQuery) {\n      if (process.env.NODE_ENV === 'development') {\n        return '[path][name].[ext]';\n      } \n      return '[contenthash].[ext]';\n    }\n  },\n  svgrOptions: {\n    ...options\n  },\n});\n```\n\n```js\nimport url, { ReactComponent as Icon } from './icon.svg';\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    \u003cIcon title=\"my awesome icon\" /\u003e\n    \u003cimg src={url} alt=\"my awesome image\" /\u003e\n  \u003c/div\u003e\n);\n```\n\n### Typescript\n\nTypescript is unable to interpret imported svg files, so `next-plugin-svgr` includes definitions\nfor svg modules depending on your use case. Per the recommendations of the Next.js maintainers you\nshould no longer reference these types in the `next-env.d.ts` file. You can instead create a `typings`\ndirectory inside your `src` directory. Then simple create a definitions file (ie: `index.d.ts`) and \nreference any of the definitions there. There shouldn't be any need to adjust your `tsconfig.json` \nfor your project.\n\n1. if using the plugin without the `fileLoader` option\n\n`src/typings/index.d.ts`\n```js\n/// \u003creference types=\"next-plugin-svgr/types/svg\" /\u003e\n```\n\n2. If using the plugin with the `fileLoader` option\n\n`src/typings/index.d.ts`\n```js\n/// \u003creference types=\"next-plugin-svgr/types/svgFileLoader\" /\u003e\n```\n\n### Contributors\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## LICENSE\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatypusrex%2Fnext-plugin-svgr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplatypusrex%2Fnext-plugin-svgr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatypusrex%2Fnext-plugin-svgr/lists"}