-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Reduce duplication of code #1723
Comments
This is one of the issues that Sapper solves. You can include util functions and other things only once and use them on desired components without duplication. |
Hi @paulocoghi thanks for the link but I don't talk about PWA's or project specific dependencies. My question is about the code generation. |
If you use a bundler it'll handle the util deduping for you as part of the usual module deduping process. |
My question is more an internal thing. When I look at the output of an component, you can see some boilerplate. Is it possible or does exists plans to reduce it even further? |
Could you share some examples of the component code you consider boilerplate? |
For example https://svelte.technology/repl?version=2.13.4&demo=hello-world
are util functions which will land in every component. If we could provide an options to deliver it in a separate file it would save a lot of space. Please have in mind that I'm talking about a scenario with lots of components 100+. This is no issue I just want to know if it was already considered. |
Those are the exact methods that won't be duplicated when using a bundler. They come from https://github.com/sveltejs/svelte/blob/master/src/shared/index.js and there will only be one copy of that for any number of components. Try adding another component in the REPL by adding another file and referencing it from the default. That boilerplate won't be repeated. |
Awesome! It's definitely worth to mention it in the docs. If you hear "no runtime" you will always think about duplication but this isn't the case. |
Initially Svelte worked this way, and there were "no runtime". But because of the duplication issue, the "standalone vs non-standalone" dilemma was solved with the |
@paulocoghi thanks for pointing out. |
Hi, based on the fact that svelte has no runtime how do you avoid that the skeleton code (e.g bootstrap code, util functions, browser tweaks) isn't shipped with every component? I understand that each component should be a self contained application but in reality I have hundreds of components in a single project. Did you ever measure this overhead? Do you think its worth to split it up for really big projects? Thanks.
The text was updated successfully, but these errors were encountered: