travel/admin/node_modules/svg-sprite-loader/examples/server-side-rendering
yaosen 242417d45d init... 2024-06-24 11:28:18 +08:00
..
build init... 2024-06-24 11:28:18 +08:00
README.md init... 2024-06-24 11:28:18 +08:00
main.js init... 2024-06-24 11:28:18 +08:00
webpack.config.js init... 2024-06-24 11:28:18 +08:00

README.md

Server side rendering example

When webpack config target option is 'node' svg-sprite-loader will use isomorphic runtime sprite module.

Demo

Input

main.js

import symbol from '../assets/twitter.svg';

// Import sprite instance which already contains twitter logo required above
import sprite from 'svg-sprite-loader/runtime/sprite.build';

// Render sprite
const spriteContent = sprite.stringify();

const pageContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
${spriteContent}

<svg viewBox="${symbol.viewBox}">
  <use xlink:href="#${symbol.id}"></use>
</svg>
</body>
</html>
`;

console.log(pageContent);

Output