build.mjs 994 B

12345678910111213141516171819202122232425262728
  1. import fs from 'fs'
  2. import { getAllIcons } from '../../.build/helpers.mjs'
  3. const icons = getAllIcons(true)
  4. const buildSprite = () => {
  5. let svgContent = ''
  6. Object.entries(icons).forEach(([type, iconsInCategory]) => {
  7. iconsInCategory.forEach(icon => {
  8. const svgFileContent = icon.content
  9. .replace(/<svg[^>]+>/g, '')
  10. .replace(/<\/svg>/g, '')
  11. .replace(/\n+/g, '')
  12. .replace(/>\s+</g, '><')
  13. .trim()
  14. svgContent += `<symbol id="tabler-${type == 'outline' ? '' : `${type}-`}${icon.name}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${svgFileContent}</symbol>`
  15. })
  16. })
  17. let svg = `<svg xmlns="http://www.w3.org/2000/svg"><defs>${svgContent}</defs></svg>`
  18. fs.mkdirSync('dist', { recursive: true })
  19. fs.writeFileSync('dist/tabler-sprite.svg', svg)
  20. fs.writeFileSync('dist/tabler-sprite-nostroke.svg', svg.replace(/stroke-width="2"\s/g, ''))
  21. }
  22. buildSprite()