Repository navigation
Description
I've spent a fair amount of time scouring the documentation and source code but I'm unable to speed up this usecase.
We're using webpack in a huge application, bordering on 1000 components, all of them fairly substantial. Our initial compile times are slow (40s), and our incremental builds are also slow (5s).
Here's a repository that seeks to emulate a test case for what I'm dealing with: https://github.com/tvararu/webpack-test.
- The entry point is
A.js, which requiresB.jsandC.js. B.jsis tiny and doesn't have a lot of dependencies.C.jsis monolithic and has thousands of requires.
My expectation is that when using webpack-dev-server in the test project, whenever I save B.js, webpack should recognize that C.js and none of its dependencies have been touched. It should compile B.js swiftly (in <10ms), replace it in the cache, and output the compiled A.js using the cached version of C.js from the initial compile.
However, webpack compiles 3002 hidden modules every time I save B.js, leading to a compile time of 960ms. This isn't bad on its own, but spirals out of control if you add some loaders like react-hot and babel, which is the case in our real project.
I do have a solution: on the same test project there is a dll branch. On that branch, you can run webpack --config webpack.dll.config.js to generate two DLLs from B.js and C.js which will then get leveraged when compiling A.js. Whenever you save B.js, its DLL will get recompiled, A.js will notice that one of its DLLs has updated and it'll just take the old DLL of C.js and the new DLL of B.js and conjoin them together into one quick happy bundle.
I could go further on that branch and do directory reads or dependency graph walks to generate a DLL for every component. That should in theory make compiling as fast as I would like it. But at that point it seems like I've just reimplemented (poorly) what the caching layer in webpack should do on its own, so what's going on here?
What blindingly obvious thing am I missing?
Thanks for reading. :)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
tvararu commentedon Nov 4, 2015
I've just submitted a question on Stack Overflow as well for this issue.
sokra commentedon Nov 14, 2015
It doesn't recompile all the modules. It only reresolves all modules.
[-]Webpack recompiles modules that shouldn't be dirty[/-][+]Webpack reresolves modules that shouldn't be dirty[/+]tvararu commentedon Nov 15, 2015
Thanks for the input! I have edited the issue title to reflect this.
This issue has been marked with the [bug] label; would profiling webpack using
node-inspectorlike in this issue be useful to determining the cause of the performance regression for this usecase?donaldpipowitch commentedon Feb 2, 2016
Has this ever been resolved? Can I use webpack
watchmode and get incremental builds? I see the same problem. I usebrowser-syncas my development server (as I need CSS live reloading andstyle-loaderproduces an initial flash effect when the styles are injected with a slight delay). You can clearly see that all source files are written down to file system even if just one file changes.I have a small example:
package.json:start.js:src/index.html:src/app.js:src/style.less:When I run
$ npm startnow I get:When I edit
src/style.lessnow I'd expect that webpack would only compilesrc/style.lesstodist/style.css, but all files are rewritten:donaldpipowitch commentedon Feb 4, 2016
@sokra This happens in
^2.0.6-beta, too.donaldpipowitch commentedon Feb 4, 2016
While webpack writes unchanged files to the file system, so
bs.watch('./dist/**/*.(html|js|css)').on('change', bs.reload);is unnecessarily called, thestatsobject of thewatchcallback actually contains information about which files have changed (module.built === true).I can now rewrite my example to get the actual loading behaviour I want:
compiler.watch({}, function(err, stats) { if (err) { console.error('webpack build error'); } else { console.log('webpack build', stats.endTime); + var changedModules = stats.compilation.modules.filter(function(module) { + return module.built && module.resource; + }); + var changedStyleModules = changedModules.filter(function(module) { + return module.resource.match(/\.(css|less|sass)$/); + }); + var hasOnlyStyleChanges = changedModules.length === changedStyleModules.length; + if (hasOnlyStyleChanges) { + bs.reload('*.css'); + } else { + bs.reload(); + } } }); bs.init({ server: { baseDir: './dist' } }); -bs.watch('./dist/**/*.(html|js|css)').on('change', bs.reload);Caveats:
module.resourcegives me the source file, but I think there is no way to see which files be generated out of this source file. I need to make a manual mapping (e.g. assume that.less,.sassand.cssfiles output some other.cssfile).AlexGalays commentedon Sep 8, 2016
@donaldpipowitch Thanks a lot for providing a working, complete workaround to this very annoying behavior.
webpack-bot commentedon Aug 11, 2017
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
dmnd commentedon Aug 15, 2017
To prevent the @webpack-bot from closing this, I just did some quick testing on my app that has multiple entry points. I changed a module that is only reachable by a single entry point and recorded how long it took to incrementally build.
Time taken with all entry points active: 11159ms
Time take with only one entry point active (e.g. commented out the rest): 1017ms
This is with webpack 2.2 because I haven't upgraded yet. But I can confirm the issue is not fixed as of 2.2.
webpack-bot commentedon Feb 14, 2018
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
warrenseine commentedon Feb 26, 2018
@webpack-bot Please don’t close.
BobbyBabes commentedon Jul 5, 2018
@donaldpipowitch
Isn't this because Webpack always injects certain boilerplate to files ?
Just a wild guess though.
webpack-bot commentedon Jan 4, 2019
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
webpack-bot commentedon Jan 19, 2019
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.