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

Failed to cache .less files on Win 10 with Webpack 4 #17

Closed
Tao-Oak opened this issue Oct 9, 2019 · 3 comments
Closed

Failed to cache .less files on Win 10 with Webpack 4 #17

Tao-Oak opened this issue Oct 9, 2019 · 3 comments

Comments

@Tao-Oak
Copy link

Tao-Oak commented Oct 9, 2019

We used SRL with Webpack 3, and it worked well both on Windows and Ubuntu. After we upgraded Webpack from 3 to 4, there is a significant improvement for incremental build speed on Ubuntu. But for windows, this is not the case. It took ~30s for every incremental build on windows. Through examining the Webpack log and some simple tests, we found that SRL caused .less files to rebuild on every incremental build. Here is the minimal reproducible repo with two branches, one use SRL, and one use @import to load the baseStyle.less file.

After some debugging, we found that SRL uses glob to match the patterns option and returns Unix style file path like D:/you/path/to/less/file.less. It then adds this Unix style file path to the dependency list of the current module. While the needRebuild method which controls the cache behavior of Webpack uses windows style file path on windows.

TheneedRebuild method has two parameters: fileTimestamps and contextTimestamps, which both are filePath -> timestamps Map. The keys of these two Maps are windows style file path like D:\\you\\path\\to\\less\\file.less, and the values are timestamps when the corresponding file was updated.

Due to the mismatch of these two file path styles, the needRebuild method returns false every time and thus .less files rebuild on every incremental build.

@yenshih
Copy link
Owner

yenshih commented Oct 10, 2019

Great analysis, will fix it soon. thanks!

@yenshih
Copy link
Owner

yenshih commented Oct 22, 2019

Hi! I have spent some time trying to figure out this problem.
It seems webpack has updated a bunch of code in these few days.

Actually I don't have a Windows PC to reproduce. I was just wondering if you could point out how wepack

controls the cache behavior of Webpack uses windows style file path on windows

Probably related source code:
https://github.com/webpack/loader-runner/blob/master/lib/LoaderRunner.js#L284
https://github.com/webpack/webpack/blob/master/lib/NormalModule.js#L467
https://github.com/webpack/webpack/blob/master/lib/FileSystemInfo.js#L708

@Tao-Oak
Copy link
Author

Tao-Oak commented Dec 16, 2019

For webpack 4, it use the needRebuild method to control the cache behavior, here is code location of webpack v4.41.2.

For webpack 5, needRebuild was deprecated but use needBuild insteand,here is the code.

For the case you don't have a Windows PC to reproduce this problem, I will create a PR to fix it latterly.

Tao-Oak pushed a commit to iaerac/style-resources-loader that referenced this issue Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants