Webpack5 File caching cannot be used in production mode with custom compilers
See original GitHub issueBug report
I have submitted this question in stackoverflow, but I haven’t received any reply。
What is the current behavior?
First, I use a custom compiler like “const compiler = webpack (config)”; compiler.run () ”。
Second, I have successfully upgraded to webpack 5 and have been able to compile successfully in production mode.
Third, I use the persistent caching mechanism of webpack5 in production mode, and configure it according to the following configuration, hoping to integrate it into our CI process.
Fourth, I found that the cache file could not be generated in my directory as expected. There was no difference in the build time between the first build and other builds. It seems that the cache was not successfully used. Fifthly, I use the development mode, the same webpack configuration, and start the service through webpack dev server. I can generate the cache file as expected, and the other times of construction time is much less than the first time. It seems that the cache is successful.
cache: { name:"testCache", type: 'filesystem', cacheDirectory: path.resolve(paths.cachePath,'webpackcache'), },
If the current behavior is a bug, please provide the steps to reproduce.
Because of the problem of office environment, I can’t code to GitHub warehouse. All I can offer is a few configuration fragments
What is the expected behavior?
File caching can be used successfully in production mode.
Other relevant information: webpack version: 5.11.0 Node.js version: v10.15.3 Operating System: window 10 Additional tools:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
You need run
compiler.run()
andcompiler.close()
(here compiler starts to store cache), example https://github.com/webpack/webpack/blob/master/lib/webpack.js#L125Wow, that’s cool! It worked. My second build time was reduced by 80%! Thank you very much!