DOM SVG Loader
DOM SVG Loader is a library inteded for web applications that runs both in a Node server and in the client (A.K.A. Isomorphic or Universal web apps). It provides a hook to handle .svg
files in the node server, and then a webpack loader to handle them in the client. It provides a function to render the svg
s under a <defs>
tag, so svg
s appears once in the final HTML and then portions of your application requiring them will just use the use
tag and will point to the required svg
.
DOM SVG Loader uses SVGO to compress your svg
s so final HTML being rendered will be fully optimized.
Install
npm install dom-svg-loader
Usage
dom-svg-loader
will inject svgs required in the dom as "symbols", and then will use a reference to those icons from the required elements
Webpack
loaders: test: /\.svg$/ loader: 'dom-svg-loader' ;
Code
Before everything
;;
Some random component
;; const mySvg = { return <MyIcon />;};
Will output:
The render method
;; { const spriteContent = await sprites; ` <!DOCTYPE html> <html> <body> </body> </html> `;}
Will output:
License
MIT