Webpack 4.0
github.com
github.com
People like to gripe about webpack and JS bundlers in general. At my last company, before webpack and browserify had really caught on (and before a bunch of other bundlers even existed), I crafted us a custom JS build solution using Make. It had just the right amount of smarts (but was mostly a dumb concatenator and wrapper), and was extremely fast and simple. Basically, it was a cranky old HN poster's wet dream.
And you know what? It still fucking sucked. We had to vendor most of our dependencies and then manually edit their source code to modify references, because Make doesn't understand JS dependencies or module resolution. We couldn't expose or even check for globals like `require` or `define` because we were third-party JS living on other people's sites with their own JS, and any accidental intermingling could break their shit, or our shit.
webpack solves all of that. It is absolutely necessary and anyone who says otherwise doesn't understand the problem space. So cheers on another release!
I'm not really up to speed on this side of things so I'd like to hear you and other view points on how webpack is shaping up against say brunch[1]? (which I'm kind of partial to)
`sideEffects` explicitly tells webpack whether it's safe to remove unused exports from a module, because it's always possible that code relies on them implicitly.
EDIT: I'm just going to link to the official docs (which don't mention `sideEffects` yet) because my last example was slightly wrong: https://webpack.js.org/guides/tree-shaking/#caveats
To work around the caveat mentioned in the docs above, the module author can include `sideEffects: false` in their package.json to notify webpack that excluding certain code is safe.
As an example, I just built a file that does:
import { compose } from 'redux';
console.log(compose);
`compose` is a really tiny no-dependency utility from Redux. The resulting bundle is 2.12 KiB. That's because webpack isn't sure whether all the other stuff exported from Redux causes any side-effects.If I edit Redux's `package.json` to specify `sideEffects: false` and rebuild, the bundle size goes down to 799 bytes: only `compose` itself is included! There are pull requests happening all across the JS ecosystem to add this flag to popular dependencies.
See this issue for more details: https://github.com/webpack/webpack/issues/2867
So if you're a library author and you know none of your modules contain side-effects, you can set `sideEffects: false` and anyone using webpack with your library will benefit. :)
Used it for openEtG until a few months ago, where switched from pixi.js to React, & switched to webpack. The 2 minute build time compared to basically-instant was a bit of a hassle, but now we support IE
I think what we have here is the start of a new era for heisenbugs to thrive.
The reason I suspect so is because a lot of JavaScript packages are written in awkward ways that makes lots of assumptions about the packages loaded, the order of the load, monkey patching require, and a whole lot of other oddities.
With current setup, you can disable various plugins and optimizations to pin point the conditions under which a bug manifests.
With new release, now you have to figure out what is the current state of the configurations to begin-with and how changing modes impacts that.
But I get your point. There might be problems if people start using it without understanding the internals.
And therein lies the bigger problem. As long as this cancerous code style is tolerated, we'll be putting workarounds on top of other workarounds instead of making actual progress.
First build:
Parcel: 23.9s, 422K output size
webpack 4: 9.6s, 399K output size
Rebuild (cached, no changes): Parcel: 900ms
webpack 4: 1400msI'm not a webpack contributor, but I'd rather get a new version into everyone's hands sooner rather than wait for random third-party developers not associated with the project to get their stuff in order.
If its a matter of putting it in the hands of users sooner than later, that's what a beta period is for. Releasing this before the documentation is even ready is just irresponsible.
You: Yarn, Bower, Babel, typescript, grunt, webpack 1, npm 5.7, webpack 2 & 3, Browserify, React, and... Gulp.
And Grunt.
Me: java EE.
Real talk, this is the modern stack:
If you want to write a simple animation or calculation on a: Javascript. Nothing else.
You have several behaviors on your page and and to use modern code practices: Babel. That's it.
You want a complicated Web app with Rich functionality on several pages: React, Webpack, Babel. That's it.
Typescript can replace Babel, if you like strong typing.