Skip to content
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

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

Closed
worlddai opened this issue Jan 6, 2021 · 5 comments
Closed

Comments

@worlddai
Copy link

worlddai commented Jan 6, 2021

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:

@webpack-bot
Copy link
Contributor

For maintainers only:

  • webpack-4
  • webpack-5
  • bug
  • critical-bug
  • enhancement
  • documentation
  • performance
  • dependencies
  • question

@alexander-akait
Copy link
Member

alexander-akait commented 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

@worlddai
Copy link
Author

worlddai commented 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!

sorrycc added a commit to umijs/umi that referenced this issue Mar 25, 2021
* fix: webpack5 build 模式下没有生成物理缓存

see
webpack/webpack#12345 (comment)

Closes #6266

* Update packages/bundler-webpack/src/index.ts

* Update packages/bundler-webpack/src/index.ts

Co-authored-by: chencheng (云谦) <sorrycc@gmail.com>
@slorber
Copy link

slorber commented Mar 25, 2021

@alexander-akait I found this doc not very clear regarding when we should use close() or not: https://webpack.js.org/api/node/#webpack

It somehow let us think that close() is only useful for the watch mode, maybe it would be useful to add an example using run() ?

@alexander-akait
Copy link
Member

@slorber Yes, feel free to open an issue or send a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants