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

Poor tree-shaking #1953

Open
rkyoku opened this issue Aug 30, 2024 · 2 comments
Open

Poor tree-shaking #1953

rkyoku opened this issue Aug 30, 2024 · 2 comments
Assignees
Labels
help wanted Extra attention is needed investigate The issue needs further investigating svelte Related to the svelte adapter vue 3 Related to the vue 3 adapter

Comments

@rkyoku
Copy link

rkyoku commented Aug 30, 2024

Version:

  • @inertiajs/svelte version: 1.2.0

Describe the problem:

1. The router

Just importing the router (@inertiajs/core) instantly adds 110KB to the final, minified uncompressed, "lib" in Svelte.

==> allow for a better tree-shaking of the router, as it shouldn't weigh 110KB minified (it probably includes some axios stuff and also other modules that increase weight)

I don't yet have a workaround for reducing output file when using the router (which is almost mandatory in any real app), but would definitely be grateful for one

2. useForm

Also, importing any module from @inertiajs/svelte prevents tree-shaking from removing unneeded stuff (e.g. useForm, which adds 30KB minified uncompressed because of lodash, even when we never use useForm)

==> maybe either use lodash-es, or don't include useForm in index.js

What I ended up doing is importing single .js files directly, e.g.:

// not good:
// import { inertia } from '@inertiajs/svelte'
// good:
import { default as inertia } from '/node_modules/@inertiajs/svelte/src/link.js'

Steps to reproduce:

Just import Inertia and check output file weight (using lib mode)

import { router } from '@inertiajs/core';
// just make sure tree-shaking believes we are actually using the router
if (router) console.log('router');
@rkyoku rkyoku added the svelte Related to the svelte adapter label Aug 30, 2024
@pedroborges
Copy link
Collaborator

Thanks for reporting it @rkyoku, I'll be looking into this as part of the v2 work 👍

@Qoraiche
Copy link

Qoraiche commented Sep 2, 2024

Thanks for reporting it @rkyoku, I'll be looking into this as part of the v2 work 👍

@pedroborges This might be a bit off-topic, but could you let me know when version 2 will be released?

@pedroborges pedroborges added investigate The issue needs further investigating help wanted Extra attention is needed vue 3 Related to the vue 3 adapter labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed investigate The issue needs further investigating svelte Related to the svelte adapter vue 3 Related to the vue 3 adapter
Projects
None yet
Development

No branches or pull requests

3 participants