extracting-runtime-generator.js 687 B

12345678910111213141516171819
  1. const { generateSpritePlaceholder, stringify } = require('../../lib/utils');
  2. module.exports = function runtimeGenerator({ symbol, loaderContext }) {
  3. // this will be replaced with real symbol url, e.g. sprite.svg#twitter-usage
  4. const publicPath = loaderContext._compiler.options.output.publicPath;
  5. const spritePlaceholder = generateSpritePlaceholder(symbol.request.file);
  6. const viewBoxParts = symbol.viewBox.split(' ');
  7. const width = parseInt(viewBoxParts[2], 10);
  8. const height = parseInt(viewBoxParts[3], 10);
  9. const data = {
  10. width,
  11. height,
  12. viewBox: symbol.viewBox,
  13. url: publicPath + spritePlaceholder
  14. };
  15. return `export default ${stringify(data)}`;
  16. };