-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite still outputs SVG assets during build #8
Comments
I will take a look |
FYI I couldn't find a good way to influence Vite or Rollup to modify this. {
name: 'svg-asset-remover',
generateBundle(_, bundle) {
// do not emit svg assets as they have been packed by svgPlugin
for (const file in bundle) {
if (bundle[file].type === 'asset' && file.endsWith('.svg'))
delete bundle[file]
}
}
} You could re-use this but instead of removing all files ending with The big defect with this approach is that it potentially could remove an SVG asset that was added another way and was not handled by |
Thank you @jods4! I'm developing an extension for Azure DevOps which doesn't allow svg files for some reason so the fact that they are still being created was a major pain in my back. @meowtec Would it be possible to get something like what @jods4 suggested into the main plugin? I'm not super knowledgeable in rollup/vite plugins but would be willing to help out on a pull request if needed. |
@meowtec any movement on this? |
Follow #8 (comment), the code should be like const transformedFilePaths = new Set<string>();
const plugin: Plugin = {
name: 'svg-sprite',
async transform(src, filepath) {
if (!micromatch.isMatch(filepath, match, {
dot: true,
})) {
return undefined;
}
transformedFilePaths.add(filepath);
},
generateBundle(_, bundle) {
for (const file in bundle) {
// file or bundle[file] can not match transformedFilePaths, they have difference formats
if (hasTransformed(file, bundle[file]))
delete bundle[file]
}
},
} There is no good way to detect whether a svg file (the The item of |
Maybe you can try this plugin |
@AFine970 thanks, I'll keep that plugin in mind. One thing I like in |
This plugins works great, but I noticed that when you build, SVG assets that were handled by
vite-plugin-svg-sprite
are still all copied into the output assets directory, although they're not needed.Any idea how to avoid that?
The text was updated successfully, but these errors were encountered: