
Research
wget to Wipeout: Malicious Go Modules Fetch Destructive Payload
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
rollup-plugin-svg-sprites
Advanced tools
Rollup plugin for creating SVG sprites.
PS:该插件是基于 svg-baker
和 svg-baker-runtime
的,跟 svg-sprite-loader
同根同源,基本可以认为是从 webpack 转到 rollup 上,可以减少避免自己踩坑。
The plugin dependencies svg-baker
. It requires @rollup/plugin-commonjs
.
// npm
npm i rollup-plugin-svg-sprites -D
// yarn
yarn add rollup-plugin-svg-sprites -D
The plugin dependencies svg-baker
. It requires @rollup/plugin-commonjs
.
// npm
npm i @rollup/plugin-commonjs -D
// yarn
yarn add @rollup/plugin-commonjs -D
Add the type definitions in *.d.ts
:
declare module '*.svg?vueComponent' {
import { Component } from 'vue'
const src: Component
export default src
}
declare module '*.svg?jsx' {
import { ReactElement } from 'react'
const src: ReactElement<any, any>
export default src
}
rollup.config.js
:
import svgSprites from 'rollup-plugin-svg-sprites'
import commonjs from '@rollup/plugin-commonjs'
export default {
input: './src/index.js',
output: {
format: 'esm',
file: 'dist/bundle.js'
},
plugins: [
commonjs(),
svgSprites()
]
}
foo.js
:
import MyIcon from './my-icon.svg'
// <svg><use xlink:href="#${MyIcon.id}"></use></svg>
vite.config.js
:
import svgSprites from 'rollup-plugin-svg-sprites'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
svgSprites({
exclude: ['node_modules/**']
})
]
})
Vue SFC
:
<template>
<MyIcon />
</template>
<script setup>
import MyIcon from './my-icon.svg?vueComponent'
</script>
vite.config.js
:import svgSprites from 'rollup-plugin-svg-sprites'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
svgSprites({
include: ['./icons']
})
]
})
App.jsx
:import MyIcon from './my-icon.svg?jsx'
function App() {
return (
<div className="App">
<MyIcon />
</div>
);
}
export default App;
eg from vfox:
rollup.config.js
:import svgSprites from 'rollup-plugin-svg-sprites'
import requireContext from '@godxiaoji/rollup-plugin-require-context'
function kebabCase2PascalCase(name) {
name = name.replace(/-(\w)/g, (all, letter) => {
return letter.toUpperCase()
})
return name.substr(0, 1).toUpperCase() + name.substr(1)
}
export default {
input: './src/load-svg.js',
output: {
format: 'esm',
file: `lib/load-svg.js`,
banner: '/* eslint-disable */'
},
plugins: [
requireContext(),
svgSprites({
symbolId(filePath) {
const paths = filePath
.replace(/\\/g, '/')
.split('assets/icons/')[1]
.split('/')
const fileName = paths.pop().replace('.svg', '')
return (
'icon-' + kebabCase2PascalCase([fileName].concat(paths).join('-'))
)
}
})
],
}
./src/load-svg.js
:const req = require.context('./assets/icons', true, /\.svg$/)
rollup -c
Vue SFC
:<template>
<svg>
<use xlink:href="#icon-My"></use>
</svg>
</template>
<script setup>
import './lib/load-svg'
</script>
How id attribute should be named.
eg:
svgSprite({
symbolId(path, query) {
return path.basename(path)
}
})
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore.
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on.
Default: false
If true, when import ".svg" will return a Vue3.x Component. Priority level is weaker than import ".svg?vueComponent".
Default: false
If true, when import ".svg" will return a JSX Function. Priority level is weaker than import ".svg?jsx".
PS:
>=17.0.0
, >=16.14.0
or >=15.7.0
.FAQs
Rollup plugin for creating SVG sprites.
The npm package rollup-plugin-svg-sprites receives a total of 503 weekly downloads. As such, rollup-plugin-svg-sprites popularity was classified as not popular.
We found that rollup-plugin-svg-sprites demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.