haruaki07 / phosphor-svelte

A clean and friendly icon family for Svelte
MIT License
120 stars 7 forks source link

feat: optimize import preprocessor #18

Closed haruaki07 closed 6 months ago

haruaki07 commented 6 months ago

This PR add a preprocessor to replace import icons with named export into default export. This processor will only match named import statements using a simple RegEx.

In short, importing icons like this:

<script>
  import { Cube, Heart, Horse } from "phosphor-svelte"
</script>

will be replaced into this:

<script>
  import Cube from "phosphor-svelte/lib/Cube"
  import Heart from "phosphor-svelte/lib/Heart"
  import Horse from "phosphor-svelte/lib/Horse"
</script>

Type Import & Alias

The processor also handles type imports (separated) and import alias, for example:

<script>
  import { Cube as IconCube, type IconContextProps } from "phosphor-svelte"
</script>

will be replaced into this:

<script>
  import IconCube from "phosphor-svelte/lib/Cube";
  import type { IconContextProps } from "phosphor-svelte";
</script>