Gathering detailed insights and metrics for next-plugin-svgr
Gathering detailed insights and metrics for next-plugin-svgr
Gathering detailed insights and metrics for next-plugin-svgr
Gathering detailed insights and metrics for next-plugin-svgr
npm install next-plugin-svgr
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
36 Stars
107 Commits
3 Forks
1 Watching
4 Branches
2 Contributors
Updated on 10 Nov 2024
JavaScript (40.2%)
TypeScript (33.75%)
CSS (23.42%)
Shell (2.62%)
Cumulative downloads
Total Downloads
Last day
11.1%
2,512
Compared to previous day
Last week
8.5%
11,204
Compared to previous week
Last month
13.6%
45,258
Compared to previous month
Last year
65%
439,615
Compared to previous year
Flexible Next.js plugin for transforming svg's into react components using the svgr library
npm
npm install --save next-plugin-svgr
or yarn
yarn add next-plugin-svgr
Create a next.config.js
in your project
1// next.config.js 2const withSvgr = require('next-plugin-svgr'); 3 4module.exports = withSvgr();
Optionally add Next.js configuration as a parameter
1// next.config.js 2const withSvgr = require('next-plugin-svgr'); 3 4module.exports = withSvgr({ 5 webpack(config, options) { 6 return config; 7 }, 8});
Or with next-compose-plugins
when composing multiple plugins
1// next.config.js 2const withPlugins = require("next-compose-plugins"); 3const withSvgr = require("next-plugin-svgr"); 4 5module.exports = withPlugins([ 6 withSvgr 7 // your other plugins here 8]);
And now in your components you can use the svg as a component
1import Icon from './icon.svg'; 2 3export default () => ( 4 <div> 5 <Icon /> 6 </div> 7);
The plugins supports all available options of svgr webpack loader. Check out the svgr documentation for the full list of options.
Example with options:
1module.exports = withSvgr({
2 svgrOptions: {
3 titleProp: true,
4 icon: true,
5 svgProps: {
6 height: 'auto',
7 },
8 },
9});
You can optionally specify a project configuration file. SVGR uses cosmiconfig for configuration file support, which means that any file type accepted by cosmicconfig is supported.
note: The plugin will automatically detect your config file so you shouldn't have to include the configFile
property in svgrOptions
. The option to specify exists and can be accomplished following the example below.
1// .svgrrc.js
2module.exports = {
3 icon: true,
4 expandProps: false,
5};
6
7// next.config.js
8module.exports = withSvgr({
9 svgrOptions: {
10 configFile: path.resolve(__dirname, '.svgrrc.js'),
11 },
12});
13
14// or with next-compose-plugins
15module.exports = withPlugins([
16 withGraphql,
17 [withSvgr, {
18 svgrOptions: {
19 configFile: path.resolve(__dirname, '.svgrrc.js'),
20 },
21 }],
22]);
If you would like to use the svgr webpack loader with file-loader.
Accepts a boolean
or all available options for file-loader.
The fileLoader
option is undefined
by default. If defined, it will apply the options below.
note: If using file-loader
and typescript remember to reference the svgr/file-loader types. See below.
Default options:
{
limit: 8192,
publicPath: `${assetPrefix ?? ''}/_next/${path}`,
outputPath: `${isServer ? '../' : ''}${path}`,
name: '[path][name].[hash].[ext]',
}
1module.exports = withSvgr({
2 fileLoader: true,
3 svgrOptions: {
4 ...options
5 },
6});
1module.exports = withSvgr({ 2 fileLoader: { 3 limit: 16384, 4 name(resourcePath, resourceQuery) { 5 if (process.env.NODE_ENV === 'development') { 6 return '[path][name].[ext]'; 7 } 8 return '[contenthash].[ext]'; 9 } 10 }, 11 svgrOptions: { 12 ...options 13 }, 14});
1import url, { ReactComponent as Icon } from './icon.svg'; 2 3export default () => ( 4 <div> 5 <Icon title="my awesome icon" /> 6 <img src={url} alt="my awesome image" /> 7 </div> 8);
Typescript is unable to interpret imported svg files, so next-plugin-svgr
includes definitions
for svg modules depending on your use case. Per the recommendations of the Next.js maintainers you
should no longer reference these types in the next-env.d.ts
file. You can instead create a typings
directory inside your src
directory. Then simple create a definitions file (ie: index.d.ts
) and
reference any of the definitions there. There shouldn't be any need to adjust your tsconfig.json
for your project.
fileLoader
optionsrc/typings/index.d.ts
1/// <reference types="next-plugin-svgr/types/svg" />
fileLoader
optionsrc/typings/index.d.ts
1/// <reference types="next-plugin-svgr/types/svgFileLoader" />
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 1/5 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More