UNPKG

stencil-inline-svg

Version:

A Stenciljs plugin to insert inline SVGs into components

22 lines (21 loc) 674 B
import * as util from './util'; export function inlineSvg() { return { name: 'inlineSvg', transform(sourceText, fileName) { if (!util.usePlugin(fileName)) { return null; } if (sourceText === '') { throw new Error('/** inlineSvg error: the SVG file is empty **/'); } return new Promise((resolve) => { const svgCode = util.decodeBase64SourceText(sourceText) || sourceText; resolve({ id: fileName, code: `export default \`${svgCode}\``, }); }); }, }; }