svg-to-symbol-loader
A webpack loader JUST to transform SVG files to symobl strings, then you can freely handle them.
JUST SUPPORT WEBPACK 4.
Rollup version: fjc0k/rollup-plugin-svg-to-symbol
Install
# Yarn yarn add svg-to-symbol-loader -D # npm npm i svg-to-symbol-loader -D
Usage
// webpack.config.jsmoduleexports = module: rules: test: /\.svg$/ use: 'svg-to-symbol-loader'
// sprite.js '<svg><defs>' add close '</defs></svg>'
The default export just likes:
..... .....
Options
- extractId
- Type:
({ name }) => id
- Default:
({ filePath, name }) => name
- Desc: Use the function to custom symbol id. The
name
is the SVG filename without the extension. e.g.
- Type:
// webpack.config.js { return `icon-` }
// the add likes:// <symbol id="icon-add">...</symbol>