2023-01-18 21:22:18 +01:00
|
|
|
import { extname } from 'path';
|
2023-01-09 23:33:27 +01:00
|
|
|
|
2023-01-18 21:22:18 +01:00
|
|
|
const injectNode = (svg) => `
|
2023-01-09 23:33:27 +01:00
|
|
|
export default function() {
|
|
|
|
return (new DOMParser().parseFromString(${svg}, 'image/svg+xml'));
|
|
|
|
};
|
2023-01-18 21:22:18 +01:00
|
|
|
`;
|
2023-01-09 23:33:27 +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
|
|
|
}
|