tabler-icons icon indicating copy to clipboard operation
tabler-icons copied to clipboard

icons-svelte builds ALL icons, even ones not used

Open silveltman opened this issue 1 year ago β€’ 34 comments

I'm using @tabler/icons-svelte in my sveltekit project and astro project. When building, it logs the following:

building client 
transforming (8344) ../../sveltekit/fulldev-ui/node_modules/@tabler/icons-svelte/dist/svelte/icons/IconWand.svelte

The above is 1 moment in the build. It takes about 30-60 seconds and goed over every icon

Is this supposed to happen?

silveltman avatar May 22 '23 13:05 silveltman

Hey, this relates to #518 and it's at unknown state 😿

PudottaPommin avatar Jun 05 '23 06:06 PudottaPommin

You'll also notice in dev mode it loads the full 24-25MB (unless you specifically call each icon by it's full @tabler/icons/svelte/dist/svelte/icons/IconName.svelte path. This causes a pretty big delay in even just refreshing a page in dev mode.

kwhitley avatar Jul 31 '23 07:07 kwhitley

same issue here it just bundles everything

alpap avatar Sep 17 '23 21:09 alpap

any word on this? i'm going to stop using Tabler because I can't bear waiting many seconds for each file change with HMR

danawoodman avatar Dec 20 '23 19:12 danawoodman

any word on this? i'm going to stop using Tabler because I can't bear waiting many seconds for each file change with HMR

As a workaround you can import them like " import IconBattery from '@tabler/icons-svelte/dist/svelte/icons/IconBattery.svelte';" But typescript complains a lot.

ttmx avatar Dec 26 '23 01:12 ttmx

the combo of no import auto complete and broken typescript types makes this untenable, ended up moving to use Lucide which ironically has the same issue but only loads 7mb instead of the 40mb

is the root export a barrel file like it is with lucide? if so, afaik tree shaking won't work

danawoodman avatar Dec 26 '23 19:12 danawoodman

yeah everything is exported via a barrel file so assuming the issue is lack of proper tree shaking

https://github.com/tabler/tabler-icons/blob/master/packages/icons-svelte/src/tabler-icons-svelte.js

perhaps an export file can be auto generated?

danawoodman avatar Dec 26 '23 20:12 danawoodman

It is definitely hacky, it was just the way I had to make it work, I like tabler icons a lot. I feel this change is much more needed than any new icon, but I don't speak for everyone.

ttmx avatar Dec 26 '23 20:12 ttmx

No news here ?

BahaaZidan avatar Jan 15 '24 22:01 BahaaZidan

I'm working on it here: https://github.com/tabler/tabler-icons/pull/969 πŸ™‚

codecalm avatar Jan 15 '24 22:01 codecalm

@codecalm Any update on this? I have seen that you closed your PR and remove the branch. πŸ‘€

sapkra avatar Feb 08 '24 13:02 sapkra

@sapkra I've moved it to #993 as a part of biggest improvements

codecalm avatar Feb 08 '24 13:02 codecalm

@codecalm is this fix availalbe in the version 3.0.0-alpha.1 already?

TheEisbaer avatar Feb 14 '24 09:02 TheEisbaer

I tested 3.0.0-alpha.1 and the issue is still there, all icons are built regardless of how many you are using.

Plorenzo avatar Feb 14 '24 11:02 Plorenzo

Temporary fix :

Set to this version in package.json :

"@tabler/icons-svelte": "2.30.0",

MarArMar avatar Feb 23 '24 18:02 MarArMar

Temporary fix :

Set to this version in package.json :

"@tabler/icons-svelte": "2.30.0",

I tried it out and it's actually not true. When you run a Vite build it still transforms all icons if you use the named imports from @tabler/icons-svelte directly.

mcmxcdev avatar Mar 08 '24 00:03 mcmxcdev

@mcmxcdev It fixes my problem and my problem (https://github.com/tabler/tabler-icons/issues/1003) was marked as a duplicate to this one by @BG-Software-BG

So maybe my problem was wrongly marked as a duplicate then

MarArMar avatar Mar 09 '24 06:03 MarArMar

@sapkra I've moved it to #993 as a part of biggest improvements

Hey @codecalm, 3.0 is out and the issue is still happening.

It would be great if you can share if there is any plans to address this soon or not, so people can decide if they can wait or they need to find other solutions.

It's clear there is quite a bit of us waiting for some clarity on this :)

Plorenzo avatar Mar 11 '24 11:03 Plorenzo

You can just define your icons like import IconBolt from '@tabler/icons-svelte/icons/bolt' for the time being until this issue is resolved.

mcmxcdev avatar Mar 11 '24 12:03 mcmxcdev

@Plorenzo I dont have to much experience with Svelte and build process with it, so if you have any ideas create PR with solution, please

codecalm avatar Mar 11 '24 21:03 codecalm

I've fixed it in #1039

import IconAd from "@tabler/icons-svelte/IconAd.svelte";
import IconAdOff from "@tabler/icons-svelte/IconAdOff.svelte";
import IconAdFilled from "@tabler/icons-svelte/IconAdFilled.svelte";

Results:

> vite build

vite v5.1.4 building for production...
βœ“ 32 modules transformed.
dist/index.html                  0.40 kB β”‚ gzip: 0.28 kB
dist/assets/index-DzadqsTt.css   1.04 kB β”‚ gzip: 0.56 kB
dist/assets/index-Cg3TY0qG.js   13.24 kB β”‚ gzip: 4.80 kB
βœ“ built in 293ms

codecalm avatar Mar 12 '24 01:03 codecalm

Version 3.0.0:

Importing icons like this

import IconEdit from '@tabler/icons-svelte/icons/edit';
import IconTrash from '@tabler/icons-svelte/icons/trash';

Results in:

vite v5.1.6 building SSR bundle for production...
βœ“ 225 modules transformed.
vite v5.1.6 building for production...
βœ“ 208 modules transformed.

Importing icons like this

import { IconEdit, IconTrash } from '@tabler/icons-svelte';

Results in:

vite v5.1.6 building SSR bundle for production...
βœ“ 5412 modules transformed.
vite v5.1.6 building for production...
βœ“ 5395 modules transformed.

Named imports results in all icons in the icon pack being transformed during build

TheEisbaer avatar Mar 12 '24 06:03 TheEisbaer

I've found a "solution" to this issue over at lucide-icons lucide-icons/lucide#1944 :

function tablerSvelteImportOptimizer(): import('vite').Plugin {
	return {
		name: 'tabler-svelte optimizer',
		transform(code, id) {
			const ms = new MagicString(code, { filename: id });
			ms.replace(
				/([ \t]*)import\s+\{([^;]*?)\}\s+from\s+['"]@tabler\/icons-svelte['"];/g,
				(match, whitespace: string, importNames: string) => {
					const hasSemi = match.endsWith(';');
					const imports = importNames
						.split(',')
						.map((v) => v.trim())
						.map((name) => {
							const path = name;
							return `${whitespace}import ${name} from '@tabler/icons-svelte/${path}.svelte'${hasSemi ? ';' : ''}`;
						});
					return imports.join('\n');
				}
			);

			if (ms.hasChanged()) {
				return {
					code: ms.toString(),
					map: ms.generateMap()
				};
			}
		}
	};
}

This converts named imports to direct imports during transforming.

TheEisbaer avatar Mar 13 '24 07:03 TheEisbaer

Did anyone try out https://github.com/tabler/tabler-icons/releases/tag/v3.0.1 which supposedly fixes this issue?

UPDATE: I tried out 3.1.0 and if you use named imports e.g. import { IconEdit } from '@tabler/icons-svelte', the issue is still present. I would like to use named imports though eventually, and I am sure others do as well since that is what this issue is about.

Before 3.0.1, import IconEdit from '@tabler/icons-svelte/icons/edit' used to work which changed to import IconEdit from '@tabler/icons-svelte/IconEdit.svelte' now which is the workaround.

mcmxcdev avatar Apr 04 '24 20:04 mcmxcdev

Any update on this? @codecalm

TheEisbaer avatar Apr 30 '24 05:04 TheEisbaer

@codecalm I have found a possible fix, but don’t know how to implement it:

you are exporting each icon separately in the package.json, that causes a huge slowdown for everything.

I have tried manually renaming every icon to Icon.svelte and doing a single export in the package.json and that improved the performance.

again, I don’t know how to implement it, but it’s worth taking a look at i guesss

TheEisbaer avatar May 16 '24 18:05 TheEisbaer

I don't know why this keeps going around in circles, but now the whole import Home from "@tabler/icons-svelte/IconHome.svelte"; has changed back, again, to import Home from "@tabler/icons-svelte/icons/home"; for anyone wondering why things are broken after updating.

rudiv avatar Jul 11 '24 16:07 rudiv

The change was implemented in response to https://github.com/tabler/tabler-icons/issues/1133

BG-Software-BG avatar Jul 11 '24 18:07 BG-Software-BG

Yeah I understand the change, it's making zero difference in editor performance at my side but the biggest pain is having to update every single import across the entire project. Because it's JS/TS, this is rather tedious and as far as I can see not documented anywhere other than that issue (and the link to it from the changelog). To me, this is a breaking change and should be documented as such.

That's why I've posted it here in case someone like myself comes frantically stumbling to this GitHub wondering why everything has suddenly broken after updating the package.

rudiv avatar Jul 11 '24 20:07 rudiv

I was also surprised about a breaking change as part of a minor release. It took me 30min to update all icon paths in our codebase and it would be nice if there was a codemod for such things to save everyone some time.

mcmxcdev avatar Jul 11 '24 20:07 mcmxcdev