docker-registry-ui/rollup/import-svg.js

29 lines
617 B
JavaScript
Raw Normal View History

2023-01-18 21:22:18 +01:00
import { extname } from 'path';
2023-01-18 21:22:18 +01:00
const injectNode = (svg) => `
export default function() {
return (new DOMParser().parseFromString(${svg}, 'image/svg+xml'));
};
2023-01-18 21:22:18 +01:00
`;
/**
* @param options
* @param options.include
* @param options.exclude
* @param options.stringify - if true returns String, otherwise returns DOM Node
*/
export default function () {
return {
name: 'import-svg',
transform: (code, id) => {
if (extname(id) !== '.svg') return null;
const content = JSON.stringify(code);
return {
code: injectNode(content),
map: { mappings: '' },
};
},
};
2023-01-18 21:22:18 +01:00
}