Closed gaearon closed 8 years ago
@mxstbr Would be great if you could take a look at it. I saw react-boilerplate
uses it but I can’t figure out how to add it. 😢
(No pressure though! I’m sure somebody will help us after open sourcing if you don’t have time. Thanks a lot for your help so far.)
Would not recommend, adds a lot of complexity. The sole benefit is that in dev mode, your builds are slightly faster if you have a lot of dependencies. (in our case it knocked off a few seconds of build time)
In production, we simply use the CommonsChunkPlugin
, which basically does the same thing automatically, it's just a bit slower since it has to figure it out, whereas with the DLL plugin we tell webpack what our vendor deps are.
Oh, okay, not a big deal then.
@mxstbr @gaearon I thought the big benefit of DLL was rebuild times. Having a faster hot-reload/rebuild when you make a change is very useful.
I did some quick and rough testing on react-boilerplate taking the commits before and after DLL was added.
Both tested in same order doing and in two different folders, right after one another. Start -> Start -> Change Footer -> Change Footer -> Change Footer -> Change Button -> Change A
Commit | First build | second build | Rebuild 1 | Rebuild 2 | Rebuild 3 | File 2 | File 3 |
---|---|---|---|---|---|---|---|
PreDLL | 8584ms | 7740ms | 1672ms | 745ms | 551ms | 802ms | 742ms |
PostDLL | 5566ms | 6488ms | 266ms | 156ms | 230ms | 328ms | 362ms |
I feel those rebuild times are pretty significant. Its a difference between feeling instant and 'waiting' for the reload. Larger project should have even more benefit.
As this project is, in part about a great dev experience, it would make sense to me that that fast rebuilds is worth adding if it can be done in a not-so-complicated manner (would be a great example for others to follow as well)
If you can submit a PR significantly improving rebuild times in any way I will be happy to get it in.
@gaearon I implemented this in my own (large) project and in create-react-app.
On my own project it took our rebuild times from ~4000ms to ~1000ms.
However in the CRA which basically just has React in the DLL the difference is alot smaller.
Commit | First build | second build | Rebuild 1 | Rebuild 2 | Rebuild 3 | File 2 | File 2 RB |
---|---|---|---|---|---|---|---|
PreDLL | 4335ms | 4413ms | 666ms | 322ms | 598ms | 563ms | 353ms |
PostDLL | 2611ms | 2752ms | 220ms | 183ms | 144ms | 193ms | 313ms |
Creating DLL package list The list of node modules to for the DLL can either be automatically generated from the package.json (ala react-boilerplate) or manually added to an array. Automatically going through the package.json makes it easier but I found some packages (react-toolbox) can break the dll build (due to importing of sass files). Manually the user knows what is going in the DLL but has to remember to add files to the array when they add new node_modules (but they know what packages make up the dll). Any missed files just go into the regular bundle.
Weird webpack stuff
DLL's aren't used by many project. When you eject and see it, it might be confusing (although my implementation is much simpler than react-boilerplate). It also needs to be run on any update to the node_modules (I believe it can be ran as postinstall
)
Reliability React-boilerplate is the only large project I know of using DLLs. It should be getting a lot of user testing now, but as of this moment its largely untested in real world apps.
I don't have much of an answer if it's worth adding. The 'feeling' between the two rather minimal as is. However if CRA is used for something containin 10+ node_modules, the difference might be much larger.
Example with larger CRA (imports: redux, react-redux, lodash, react-bootstrap, immutable, redux-saga, reselect, babel-polyfill, react-router. No other changes)
Commit | First build | second build | Rebuild 1 | Rebuild 2 | Rebuild 3 | File 2 | File 2 RB |
---|---|---|---|---|---|---|---|
PreDLL | 6801ms | 7536ms | 1489ms | 1192ms | 816ms | 1248ms | 1226ms |
PostDLL | 2965ms | 2202ms | 633ms | 145ms | 222ms | 230ms | 241ms |
IMO it'd be nice to have, even though the gains on the minimal examples are small. It's such a pain to set up if you're unfamiliar with it, so having something working out of the box is really nice.
Shameless plug, you can look how tarec uses DLLS:
tarec dll
) that will put all the dependencies
in the package.json of the application in the dll. See the webpack config. Dlls will be generated in a .tarec
folder, where we can find themadd-asset-html-webpack-plugin
does a nice job for thatSo it's not perfect yet:
dependencies
will be included in the application. I think this is a fair assumption thoughBut I concur with @ro-savage, in my experience it yields very impressive improvements even on medium size apps with a dozen dependencies. It also improves the debugging experiences on lower-end machines in chrome because the source maps of the actual application become smaller.
I implemented it pretty quickly in a work project with similar performance gains as @ro-savage:
http://engineering.invisionapp.com/post/optimizing-webpack/ https://robertknight.github.io/posts/webpack-dll-plugins/
I don’t quite understand how to integrate it, and community help would be most welcome. It would be ideal if we could make both dev and prod builds faster.
The idea is that we’d only use it for
react
andreact-dom
.