Gathering detailed insights and metrics for @foxpro/vite-plugin-solid-svg
Gathering detailed insights and metrics for @foxpro/vite-plugin-solid-svg
Gathering detailed insights and metrics for @foxpro/vite-plugin-solid-svg
Gathering detailed insights and metrics for @foxpro/vite-plugin-solid-svg
Vite plugin to Import SVG files as Solid.js Components
npm install @foxpro/vite-plugin-solid-svg
Typescript
Module System
Node Version
NPM Version
54.2
Supply Chain
88.2
Quality
74.5
Maintenance
50
Vulnerability
98.6
License
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
81 Stars
66 Commits
10 Forks
2 Watchers
3 Branches
8 Contributors
Updated on Jan 30, 2025
Latest Version
0.5.1
Package Id
@foxpro/vite-plugin-solid-svg@0.5.1
Unpacked Size
11.71 kB
Size
4.13 kB
File Count
7
NPM Version
8.19.2
Node Version
19.0.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Extend Vite with ability to use SVG files as Solid.js components.
?component-solid
query string2.4.4 or above
1yarn add --dev vite-plugin-solid-svg 2 3pnpm i -D vite-plugin-solid-svg
1// vite.config.js 2import solidPlugin from 'vite-plugin-solid' 3import solidSvg from 'vite-plugin-solid-svg' 4import { defineConfig } from 'vite' 5 6export default defineConfig({ 7 plugins: [solidPlugin(), solidSvg()], 8})
1// tsconfig.json 2"compilerOptions": { 3 // ... 4 "types": ["vite/client", "vite-plugin-solid-svg/types"], 5},
1SolidSvg({
2 /**
3 * If true, will export as JSX component if `as` isn't specified.
4 *
5 * Otherwise will export as url, or as JSX component if '?as=component'
6 */
7 defaultAsComponent: true,
8
9 svgo: {
10 enabled: true, // optional, by default is true
11 svgoConfig: <svgo config> // optional, if defined, the file svgo.config.js is not loaded.
12 }
13})
If you need to configure svgo
, you can also create a config file svgo.config.js
in the project's root, following the instructions at svgo docs. The svgo.svgoConfig
has precedence over the file.
Import as a Solid.js component:
1import MyIcon from './my-icon.svg?component-solid'; 2// or './my-icon.svg' if `defaultAsComponent` is `false` 3import MyIcon from './my-icon.svg'; 4 5const App = () => { 6 return ( 7 <div> 8 <h1> Title </h1> 9 <MyIcon /> 10 </div> 11 ); 12}; 13 14export default App;
To import all svg inside a folder, use import.meta.glob('@/svgs/*.svg', { as: 'component-solid' })
. See Vite docs for more details.
1const icons = import.meta.glob('./*.svg', { as: 'component' }) 2 3/* 4 icons = { 5 icon1: () => import("./icon1.svg"), 6 icon2: () => import("./icon2.svg") 7 } 8*/ 9 10const App = () => { 11 const Icon1 = lazy(() => iconsDic.icon1()) 12 return ( 13 <div> 14 <p>hello</p><Icon1 /> 15 </div> 16 ); 17}; 18 19export default App;
vite add its own definition for "*.svg"
and it define them as string
. So far as I know this can't be overrided.
To propertly have type inference, you must use the imports with querystring.
1import MyIcon from './my-icon.svg'; // <-- this will match vite module definition, and therefore identified as string 2import MyIcon from './my-icon.svg?component-solid'; // <-- this will match the definition in this plugin, and therefore identified as Solid Component
In a Solidjs + vite project, you can easily add an svg image using:
1import iconUrl from './icon.svg' 2 3const App = () => { 4 return ( 5 <div> 6 <img href={iconUrl}> 7 </div> 8 ) 9} 10
However the fill color of the image cannot be overriden. Importing the svg as a component solves this and allows css styles to cascade into the svg content. Furthermore there may be situations where you'll need to ensure the image has been fully loaded, for example, before starting an animation. This module gives you a component that you can control when it's loaded.
This plugin is based on the work from the following projects:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
Found 5/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
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 2025-02-10
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