vbenjs / vite-plugin-svg-icons

Vite Plugin for fast creating SVG sprites.
MIT License
818 stars 111 forks source link

无法替换成纯名称的,代码是不是有问题 #100

Open joebnb opened 10 months ago

joebnb commented 10 months ago

https://github.com/vbenjs/vite-plugin-svg-icons/blob/7550357300793b96b3561fc708899b9f4309e906/packages/core/src/index.ts#L270C4-L270C38

用了FName 导致拿到的名称即使配置成

symbolId: '[name]',

也会永远存在 path

应该是


export function createSymbolId(name: string, options: ViteSvgIconsPlugin) {
  const { symbolId } = options

  if (!symbolId) {
    return name
  }

  let id = symbolId
  let fName = name

  const { fileName = '', dirName } = discreteDir(name)
  if (symbolId.includes('[dir]')) {
    id = id.replace(/\[dir\]/g, dirName)
    if (!dirName) {
      id = id.replace('--', '-')
    }
    fName = fileName
  }
  id = id.replace(/\[name\]/g, fileName) //这样的吧
  return id.replace(path.extname(id), '')
}
liang0-0 commented 6 days ago

+1, html里面会显示全路径, image image