Back when webpack first came out, I struggled a little bit with figuring out what it actually did. While I understand now, I am not why I would want to (or you) switch from JSPM to webpack. I don't see any features that webpack has that JSPM doesn't (and JSPM offered ES6 support well before of course, with babel on by default).
I like to use JSPM because of how relatively easy everything fits together -- and how straightforward it is to use and configure.
For those not familiar, JSPM is a package manager, module bundler, and module loader all in one for javascript applications.
This means you can:
jspm install <package>
And JSPM will look in NPM/Github (and it's possible to add registries, like bower) for stuff . That's the package management facet. jspm bundle-sfx js/main dist/build.js
Bundle your code all together, and drop it in a file <import src="system.js">
<script>
// set our baseURL reference path
System.config({
baseURL: '/app'
});
// loads /app/main.js
System.import('main.js');
</script>
Load your modules on the fly like you would with something like RequireJS.As you may have guessed, JSPM relies on SystemJS (https://github.com/systemjs/systemjs) internally for some of the features above.
This video really opened my eyes to what it could do: https://www.youtube.com/watch?v=iukBMY4apvI
Cachebusting is possible with systemjs. Looks like this project is a good start:
https://github.com/stealjs/cache-bust
Here's a quick-n-dirty fix for this same problem when working with Aurelia:
https://github.com/aurelia/framework/issues/94#issuecomment-...
Here's where SystemJS devs are discussing adding cachebusting:
what is your opinion of webpack in general though ?
Also, please look at the other responses, bundling deps seems to be the definitive answer to how to speed up JSPM. Though of course your cache busting issue is separate.
Is this not baked into every build tool out there ? How does one take care of caching while serving assets .. or is the general philosophy of JS right now around SPA (so dont care to cache) ?
JSPM just doesn't take a built-in stance on it (as of now, as I noted there is a ticket to get it included), but it certainly is configurable enough to allow you to add cache busting (by changing the loader). Not trying to apologize for JSPM -- it would certainly be better if they had some sort of cache busting option that was easily available and obvious.
I think the thought here is that when you're ready to push to production, and you build your actual bundle, you name that file whatever you need to to bust caches.
I ended up compiling the 3rd party dependencies into a single bundle, then letting JSPM run only on my app's code.
What we hate is jspm is extremely slow in development for us. There are two main causes:
- The amount of xhr. This is solvable with http2's server push (but
our dev server is in Ruby, and there's no http2 webserver yet).
- Apparently jspm doesn't cache the result of Babel's compilation,
so for each page refresh every file has to be recompiled again.
We will look at Webpack2 when it's released, if it allows us to use these legacy libraries and wins us some development speed we will not look back.Also, how long does your actual bundle time take? For small projects, I actually get away with just triggering the bundle command when appropriate files in the project change. I highly doubt it would work for you, but if you're spending 10 seconds waiting for stuff to come in over the network, and your bundle command runs in 5, you could just do that instead, and actually work with the bundled code (and generated source map)
Looks like I'm not the only one who thinks it's sometimes a good idea: https://60devs.com/optimizing--default-jspm-workflow-with-gu...
We do the same in our project: we bundle all the 3rd party libs when they change, so only our own code gets retranspiled on each page load. During deployment, we bundle all the JS in a single bundle (which is good for us, as we don't have too much JS in that project).
jspm bundle src/app.js - src/[/*]
This will tell jspm to bundle src/app.js with all its dependencies, excluding everything in the src/ directory. This will result in JSPM bundling only your dependencies.
> jspm bundle app//* - [app//*] js/tmp/dependency-bundle.js --inject --no-runtime
That tells JSPM to bundle everything except your application if your app lives within the app/ directory.
> jspm bundle babel js/tmp/bundles/babel.js --inject --skip-source-maps --minify
This tells it to bundle the Babel dependencies which aren't considered in the above.
It's so fast now.
we are serving our JS files as static assets behind nginx - we dont run nodejs on the server. does webpack allow you to create static assets (htmls,css,js) and serve them ?
the big issue is of course the fact that some libraries (Handsontable) are coming from github and are not on npm. is it possible to use them - with overrides,etc. ?
And, excuse me for saying that, but I found your post lacking in substance. Writing "It's super slow, we've tried everything" doesn't show us about what you've tried and with a detailed explanation maybe the thousands of eyeballs who saw that post would be able to help you find the problem you had. ;)
https://www.reddit.com/r/javascript/comments/42ozl3/why_we_s...