mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2025-04-26 15:09:53 +03:00
28 lines
617 B
JavaScript
28 lines
617 B
JavaScript
import { extname } from 'path';
|
|
|
|
const injectNode = (svg) => `
|
|
export default function() {
|
|
return (new DOMParser().parseFromString(${svg}, 'image/svg+xml'));
|
|
};
|
|
`;
|
|
|
|
/**
|
|
* @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: '' },
|
|
};
|
|
},
|
|
};
|
|
}
|