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

[Help/Documentation] How is three/cubed & sveltekit/vite/ssr supposed to be configured to benefit the most from treeshaking/codespilting/minification ? #28

Open
theword opened this issue Nov 28, 2021 · 1 comment

Comments

@theword
Copy link

theword commented Nov 28, 2021

Hi,

To Anyone Who Will Listen:

For a sveltekit project with a animated homepage with three.js.

With a standard svelte.config.js:
The pnpm run build reads app.js is 448.25 KiB.

However, this warning appears:

> .svelte-kit/output/server/app.js:23:7: warning: Ignoring this import because "node_modules/.pnpm/[email protected]/node_modules/three/build/three.js" was marked as having no side effects
   23 │ import "three";
      ╵        ~~~~~~~
  node_modules/three/package.json:11:2: note: "sideEffects" is false in the enclosing "package.json" file
   11 │   "sideEffects": false,

Then when the configuration changes to be the same as the cubed sample project in svelte.config.js:

ssr: {
     noExternal: ['three'],
},

This gets rid of the warning! But now the project size for the total app.js becomes 1389.12 KiB.

Additionally, if you try to use a package like three-minifier to tree shake three.js, it doesn't work with Vite. Vite should automatically optimize the three/cubed packages? This seems to be implied from cubed docs on React3 Fiber My impression is that this code from src:

optimizeDeps: {exclude: ['three']} stops Vite from optimizing any part of three.

However, both configurations seem to build. Although I don't know exactly what is happening in SSR. The Vite documentation says it "externalized for SSR".
I'm guessing we don't want SSR with three.

@babichjacob
Copy link

babichjacob commented Dec 12, 2021

The latest version of Vite (2.7) has been released and is being used by SvelteKit. You don't need to exclude three from optimization anymore.

In a playground I made, the vendor file now builds to 550.11 KiB (and adding / removing imports changes it accordingly which implies tree-shaking is working I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants