Skip to content
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

Feature request: Auto-import: Allow to handle name conflicts #353

Open
danielrentz opened this issue Nov 28, 2024 · 0 comments
Open

Feature request: Auto-import: Allow to handle name conflicts #353

danielrentz opened this issue Nov 28, 2024 · 0 comments

Comments

@danielrentz
Copy link

danielrentz commented Nov 28, 2024

Hi!

I am trying to combine this module with @gitlab/svgs. When using the auto-import feature, I am getting warnings for icon name conflicts, e.g.:

WARN  Two component files resolving to the same name SvgoStatusSuccess:
- .../node_modules/@gitlab/svgs/dist/sprite_icons/status_success.svg
- .../node_modules/@gitlab/svgs/dist/sprite_icons/status-success.svg

Yes, seven years ago they have added new icons with underscore separators that (of course) look differently.
https://gitlab.com/gitlab-org/gitlab-svgs/blob/main/sprite_icons/status_success.svg
https://gitlab.com/gitlab-org/gitlab-svgs/blob/main/sprite_icons/status-success.svg

I would like to have a way to handle this somehow, say with a callback config option that allows to generate a custom component name from the full file path:

import { basename } from "node:path"
export default defineNuxtConfig({
  svgo: {
    autoImportPath: "~~/node_modules/@gitlab/svgs/dist/sprite_icons/",
    autoImportComponentName(filePath: string, defaultName: string): string {
      // e.g.:
      // filePath === ".../node_modules/@gitlab/svgs/dist/sprite_icons/status_success.svg"
      // defaultName === "SvgoStatusSuccess"
      return basename(filePath).includes("_") ? `${defaultName}2` : defaultName
    },
  },
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant