inertia icon indicating copy to clipboard operation
inertia copied to clipboard

Poor tree-shaking

Open rkyoku opened this issue 1 year ago • 2 comments

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 avatar Aug 30 '24 00:08 rkyoku