-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Docs Request: Bundler free tutorials. #2033
Comments
The section here under "Getting started using the CLI" explains how to compile individual components, without using a bundler. All of the other examples and templates use a bundler because that really is the best way to build apps with it. This isn't unique to Svelte. Almost all modern frameworks and libraries are designed in a way that's optimized for bundlers. |
Yeah, I was able to do the first demo and then none after that because rollup is assumed in all of them. If you just try to compile, you run into problems because the examples have stuff like Re: Bundlers are best. For a small project (such as toy apps and demos) or simple components, they add complexity that is unnecessary. When my whole app/component is 2kb or less, I don't need a bundler and it just makes my build process more complicated. Also I am pretty disenchanted with bundlers overall. HTTP/2 with push makes it so there are no longer meaningful benefits to putting everything into a single file vs multiple files. There are some advantages in terms of deduping, but svelte compiler appears to have this built-in in the form of the |
Until we have 1st-class support in every browser for ES modules and web components, bundlers will keep shining. Rollup itself has sample templates for Svelte that makes you get up and running in literally less than 60 seconds. Doesn't like Rollup? Ok, there is one for Webpack too. I myself have been working on super small libs that, even being small, would be a pain in the ass to mantain without a bundler due to browsers particularities. And keep that in mind: IMO Our job as code writers is to make our code run smootly. The focus should not be if it's easy for us, but if is it simple for those who will actually use it. That's again a reason to use bundlers. But if you really want to work oldschool way, you can always compile your components and link them in your HTML file via |
My target demographic is modern browser only (things with ES module support). I was able to get the initial import (e.g., |
If I understand it correctly you need to compile all components first before you can import them respectively. That's why it works fine with single component scripts. Svelte always includes the compile step. In svelte 2 you can use the |
I did |
Ah, that was the trick. I was looking at https://github.com/sveltejs/template-custom-element/blob/master/src/main.js which uses rollup and doesn't Out of curiosity, how is it that a bundler causes the behavior to change? I wouldn't expect a bundler to have that effect. |
For future referenceCreate your component: <h1>Hello {name}</h1>
<script>
export default {
tag: 'my-app',
props: ['name']
}
</script> Compile it to a custom element: Use your component in your page <my-app name="world"></my-app>
<script type="module" src="./MyApp.js"></script> This is equivalent to: <my-app name="world"></my-app>
<script type="module">
import './MyApp.js'
</script> Check out the result! |
Svelte v3 is going to require a bundler to be able to do anything useful with your compiled components. The CLI is also removed in v3. There may eventually be a more powerful CLI added sometime in the future, but it's not currently a priority. |
Closing this. As mentioned above, you now absolutely do need a bundler with v3. Anything in this area would instead fall under something like #1667, an enhanced CLI. |
This was a beautiful thread :) A guy: Why do I need to use a bundler for anything useful? I can do only a few small things from cli. Response: cli removed entirely in v3. Nice! I learned a lot, it was a very informative thread, I was also looking for a cli. Bundlers are neccessary and btw @MicahZoltu maybe think about rollup + svelte as being compilers together and they reduce code complexity... even for small projects, once compiled the output bundle is minimal and runs directly in browser, not on another layer of indirection as with other frameworks like React. |
You definitely don't need a bundler in modern JS. All of my projects use ES6 modules and no bundler. The only runtime loader I use is the ultra-thin |
funny to bump into this thread after the svelte-kit + snowpack announcement, and seeing things going in the other direction I totally understand @MicahZoltu point about circumventing the bundler abstraction, and all of its inherent problems. When I think about all the time spent in learning and debugging bundlers it really helps to put things into perspective. |
From what I can tell, all of the documentation and samples assume that you will be using a bundler like rollup. While I can appreciate the value in having some documentation that shows how to integrate with a bundler, I would like to be able to learn svelte without yet-another-layer-of-abstraction between me and what is actually going on so I can really understand how things work. One of the things that attracted me to svelte in the first place was its claim of "plain old JavaScript generation", which I interpreted to mean "fewer tools/frameworks/libraries in the mix". At the moment, I'm trying to poke at some of the samples/templates and documentation examples without using rollup and I'm struggling with them because they all assume you'll be using rollup and including a bundle.
It would be nice if the docs included details on how to use svelte without a bundler, or at least some instructions on how to convert rollup examples to bundler-free examples so I can play around with svelte without a bundler.
The text was updated successfully, but these errors were encountered: