question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack5 File caching cannot be used in production mode with custom compilers

See original GitHub issue

Bug report

I have submitted this question in stackoverflow, but I haven’t received any reply。

https://stackoverflow.com/questions/65556873/why-cant-my-webpack5-configuration-use-filesystem-cache-in-production-mode

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
alexander-akaitcommented, Jan 6, 2021

You need run compiler.run() and compiler.close() (here compiler starts to store cache), example https://github.com/webpack/webpack/blob/master/lib/webpack.js#L125

2reactions
worlddaicommented, Jan 7, 2021

You need run compiler.run() and compiler.close() (here compiler starts to store cache), example https://github.com/webpack/webpack/blob/master/lib/webpack.js#L125

Wow, that’s cool! It worked. My second build time was reduced by 80%! Thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching
This guide focuses on the configuration needed to ensure files produced by webpack compilation can remain cached unless their content has changed.
Read more >
Why can't my Webpack5 configuration use filesystem ...
I mean, does production mode not support file caching? I intend to apply Webpack5's persistent cache to CI to speed up CI builds....
Read more >
Custom Webpack Config
Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case:.
Read more >
How to configure Webpack 4 with Angular 7
build:prod : run the Angular compiler with ngc command and then run webpack in production mode to generate your bundles. serve : I...
Read more >
Getting Started With Webpack
Plugins #. The use of plugins allows webpack compiler to perform tasks on chunks produced from the bundled modules. Although webpack is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found