-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Bake-in support for webpack DLLs #1201
base: master
Are you sure you want to change the base?
Conversation
Enables parallel loader application for jsx, json, sass, and less sources using five background threads. Some env notes: - you can disable HappyPack entirely by setting HAPPY=0 in your env - you can disable HappyPack's caching by setting HAPPY_CACHE=0 - you can make HappyPack more verbose by setting HAPPY_VERBOSE=1 (useful to see the state of cache) - HappyPack's state and cache can be reset by `rm -r .happypack/` Other minor changes: - made those loaders only apply to files under `/src` (a whitelist)
One can now benefit from more build-time speed-ups by pre-compiling vendor libraries into a DLL. To compile the DLL: npm run build-dlls To use the DLL: export WEBPACK_DLLS=1 npm run dev What isn't done: - cache busting - webpack isomorphic tools integration (if it's needed anyway, I don't use it/know it)
@amireh This looks great, looking forward to integrating it! I was curious if you ever came across this attempt at DLLs in another boilerplate, and your thoughts on their approach - |
I haven't actually, thanks for linking. The method applied here was adapted from what we did at work, and it's been working fine for us for months now (but we do not use DLLs in production for a few reasons so I didn't go into it here either but you may want to explore that avenue.) Btw, the benchmarks above were made on my main box, but I just tried it out on an old macbook and build time went down from 14271ms to 4823ms-5560ms which is actually really nice. Hardly a second or two worth of difference even though the difference in hardware is vast. |
Thanks for the perspective. One follow-up:
Could you elaborate more on those reasons so that I could inform my decision as well? |
Hmm, well the only point that would've broken the output is that the DLL contained (for convenience) all our vendor modules, while in production we use several chunks and some libraries are loaded only in certain contexts (aka on-demand), so we'd either have had to maintain multiple versions of the DLL (based on the environment) or cause users to download code they wouldn't run. Obviously, the latter is not an option. Maintaining multiple versions of the same DLL seems silly simply because the tool is really a development tool - there's no gain that I know of from using a DLL vs using a chunk (at run-time) so it's just useless work. There's also the extra request overhead... Just some things I can remember, there's probably more, but I'll leave it at that. 😁 HTH |
@amireh I think Happypack doesn't work well when doing code splitting - I could be wrong but last time I had to take it out for my js files due to that. |
@mmahalwy can you open a ticket on happypack's repo with some example? |
Is there a need to build DLLs manually? |
I build DLLS on postinstall in my fork and happypack is active by default, I went 8 seconds to 5 seconds when I run But the command for generate babel-runtime list doesn't work for me: |
Oh, that egrep -o 'babel-runtime/\S+' | sed 's/\.js$//' | sort | uniq It might be too aggressive to add And yes, the DLLs need to be compiled any time the vendor modules change. Doing it in a |
egrep -o 'babel-runtime/\S+' | sed 's/\.js$//' | sort | uniq still does not work for me, the command displays nothing and does not close. |
Err, so maybe the comment wasn't clear, but let me quote:
So you actually have to run webpack and pipe its output to that command, a la: ./node_modules/.bin/webpack --config webpack/dev.config.js | egrep -o 'babel-runtime/\S+' | sed 's/\.js$//' | sort | uniq That command basically just tries to extract any I hope it's clear now! Sorry about the confusion. |
Thanks, it's clear now |
I needed to add the webpack --config webpack/dev.config.js --display-modules | egrep -o 'babel-runtime/\S+' | sed 's/\.js$//' | sort | uniq I think we can also use production as long as there's no lazy loading, it does not stop to remove it easily later. |
var manifest = loadDLLManifest(path.join(root, 'webpack/dlls/manifests/' + dllName + '.json')); | ||
|
||
if (manifest) { | ||
console.warn('Webpack: will be using the "%s" DLL.', dllName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason this is a warning instead of a log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good reason at least!
I'm trying to create a Dll that has some files in my source code in it, like big json files. However I can't get the webpack server to serve the json file. any ideas? webpack/webpack-dev-middleware#106 |
@amireh Impressive, from ~6 to ~3, thanks ... |
@amireh I followed your changes and have run into a strange issue. Everything bundles correctly and dropped by rebuild time by about half. However, I see the DLL get built from the manifest and it ends up in dist/dlls folder but when I open up any page I get a
Any help would be much appreciated! |
@philipchmalts most likely the DLL file is just 404ing and the HTML you're seeing is from the 404 page. It's a bit confusing, but Webpack dev server will NOT serve the DLL. I don't fully understand why. Instead you have to load the DLL from the application server (for this project, port 3000), which just serves the file from disk, directly from the dist folder. In my Html.js file I do this:
which will just serve that file directly from dist from the main express webapp. In production you probably don't want to build a dll file, you probably want to use commonchunks or maybe require.ensure if you don't want to build one main file. |
I have this in my html.js
But still getting the same thing. I don't understand at which point the dll file is getting mangled to contain this.
|
@philipchmalts Try using a fully-qualified URL for the DLL, basically what @delvarworld said above which I suspect is the issue. Instead of |
@amireh @delvarworld Thanks!!! that did the trick I think, going to kick the tires on it for a bit but it looks like it works. Down from about ~4-6s to ~1-3s, was pulling my hair out about this. |
@philipchmalts nice man, glad it works! 😁 |
If ever the DLL is invalid I added a warning and support of the DLL is automatically removed: https://github.com/erikras/react-redux-universal-hot-example/compare/master...bertho-zero:progressive?expand=1#diff-375445b5a84cd461b8571395b5d4a75fR76 |
This patch bases on top of the happypack one although it's not technically related (only in domain) to squeeze out some more build-time improvement. I saw the question of applying DLLs to this project asked a lot so I thought I'd contribute an answer.
Here's a table that shows the build-time gains from using DLLs first, then HappyPack + DLLs:
The patch may be missing a few things (the ones I know are outlined in the commit message), so feel free to rip it out yourself if you need to as it's very unlikely I'll find the time to address anything around this.
What I tested and found to be functional (you would definitely be the better judge here though):
The DLL is allowed in the development build only, and the code gives room to define more DLLs if you guys want later on.
Thanks.