{
// This option will be forwarded to url-loader, can set to false to disable generation of default export
url: {
limit: 1024,
},
// Can be:
//
// 1. true: generate react component as ReactComponent named export with default option
// 2. false: don't generate react component
// 3. object: customize react code generation, see below
//
// Default to false.
react: {
// Can be multiple formats:
//
// 1. true: auto resolve a component name from resource path
// 2. false: remove display name from output
// 3. string: a static display name
// 4. function: customize display by (resourcePath) => string
//
// Default to true.
displayName: true,
}
}
By default @ecomfe/svg-mixed-loader generates only default export, behaves exactly the same as url-loader,
if ReactComponent named export is wanted, pass {react: true} as options is a quick solution.
svg-mixed-loader
Webpack loader resolving svg into url string and multiple component formats.
Background
In community svg files are commonly used to introduce icons to web apps, in this case developers are tend to import and svg as a component:
Also, svg, when itself is a common image format, may used as an image:
As these use cases are conflicting to each other, this loader sovles this by export multiple possible formats from an svg file.
Install
@ecomfe/svg-mixed-loaderrequires url-loader and file-loader as peer dependencies.Usage
Output
This loader currently create a default export of image URL, and a named export
ReactComponentas a react component.Options
By default
@ecomfe/svg-mixed-loadergenerates only default export, behaves exactly the same asurl-loader, ifReactComponentnamed export is wanted, pass{react: true}as options is a quick solution.