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

[v8] Missing tree shaking support #8112

Closed
mwskwong opened this issue Dec 6, 2022 · 11 comments · Fixed by #8332
Closed

[v8] Missing tree shaking support #8112

mwskwong opened this issue Dec 6, 2022 · 11 comments · Fixed by #8332
Labels
package Pull requests or issues that affect the NPM package

Comments

@mwskwong
Copy link

mwskwong commented Dec 6, 2022

Kind of Issue

Bug

This issue concerns the...

NPM package

Package Version

8.0.0

Other Software

None

Description

In v8, the tree-shaking capability is missing despite how the README suggests.

Steps to reproduce

  1. Install simple-icons v8.
npm install simple-icons@8.0.0
  1. Import an arbitrary icon
import { siSimpleicons } from 'simple-icons';
  1. Build the project and observe the bundle size (e.g., by using Webpack Bundle Analyzer)

Expected behavior

Tree shaking is supported, just like when we used to import icons from simple-icons/icons in v7.

@mwskwong mwskwong added the package Pull requests or issues that affect the NPM package label Dec 6, 2022
@mririgoyen
Copy link

mririgoyen commented Dec 14, 2022

Can confirm here. Tree-shaking is not currently working on v8.

Utilizing destructuring as so:

import { siGithub, siTwitter } from 'simple-icons';

Will yield the ENTIRE package ending up in the bundle.

Screenshot 2022-12-13 at 11 18 26 PM

Other libraries used in the same project tree-shake as expected.

@CaptainCodeman
Copy link

I can confirm - using with vite / SvelteKit results in a 4.4Mb JS page where an icon is used.

Changing the import to be from 'simple-icons/icons' instead of from 'simple-icons' makes TS unhappy but does only include the expected icons.

@mwskwong
Copy link
Author

Bump. I'm really surprised not many people seem to care about/aware of this

@CaptainCodeman
Copy link

Bump. I'm really surprised not many people seem to care about/aware of this

How many have done a release over Christmas and used the latest version and then noticed that their bundle size has exploded?

It doesn't break, it would just make some pages slow AFAICT

@mwskwong
Copy link
Author

mwskwong commented Dec 31, 2022

Bump. I'm really surprised not many people seem to care about/aware of this

How many have done a release over Christmas and used the latest version and then noticed that their bundle size has exploded?

It doesn't break, it would just make some pages slow AFAICT

Well, guess what, there are 10k downloads for the last 7 days alone for 8.0 or above.
image
So yeah, many people should have already used the affected version. And this issue is reported one month before Christmas.

Anyway, I just hope this issue will not get buried by the huge number of icon requests.

@michel-kraemer
Copy link

michel-kraemer commented Jan 4, 2023

For anyone, who's using Next.js 13.1: I solved this by adding the following to my next.config.js:

modularizeImports: {
  "simple-icons": {
    transform: "simple-icons/icons",
    preventFullImport: true,
    skipDefaultConversion: true
  }
},

You can do something similar with babel-plugin-transform-imports apparently.

@mwskwong
Copy link
Author

For anyone, who's using Next.js 13.1: I solved this by adding the following to my next.config.js:

modularizeImports: {
  "simple-icons": {
    transform: "simple-icons/icons",
    preventFullImport: true,
    skipDefaultConversion: true
  }
},

You can do something similar with babel-plugin-transform-imports apparently.

Are you using JS? Because TS doesn't seem to be happy when this is applied.

@michel-kraemer
Copy link

Are you using JS? Because TS doesn't seem to be happy when this is applied.

I'm using TypeScript. I don't get any errors.

@polyipseity
Copy link

I had the same issue and worked around it in esbuild with package aliasing:

await esbuild.build({
  entryPoints: ['app.js'],
  bundle: true,
  write: true,
  alias: {
    'simple-icons': 'simple-icons/icons',
  },
  treeShaking: true,
})

@mondeja
Copy link
Member

mondeja commented Feb 9, 2023

Hi, could you confirm that applying the next patch to node_modules/simple-icons/package.json the problem is solved?

develop...possible-patch-8112#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L14-R19

@polyipseity
Copy link

polyipseity commented Feb 10, 2023 via email

polyipseity added a commit to polyipseity/obsidian-terminal that referenced this issue Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package Pull requests or issues that affect the NPM package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants