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

Fix rebuilding of all virtual modules on any change for webpack 4 #78

Merged
merged 1 commit into from
Nov 27, 2020
Merged

Fix rebuilding of all virtual modules on any change for webpack 4 #78

merged 1 commit into from
Nov 27, 2020

Conversation

non25
Copy link
Contributor

@non25 non25 commented Nov 26, 2020

What's the problem this PR addresses?

Test lets us know more about virtual modules getting reloaded and rebuilt.

How did you fix it?

The problem of reloading and rebuilding every virtual module on any change is not fixed yet.

@non25 non25 changed the title Rebuild test Possible fix to reloading and rebuilding all virtual modules Nov 26, 2020
@non25
Copy link
Contributor Author

non25 commented Nov 26, 2020

I've managed to make old fix work both on webpack 4 and 5, but I can't understand how to make automated tests work too...
Would like to get some help.

Interesting, ln -sf doesn't overwrite previous symbolic link so I haven't tested anything propely...

@non25
Copy link
Contributor Author

non25 commented Nov 26, 2020

So previous fix, which consist of populating compiler.fileTimestamps Map like this:

Object.keys(virtualFiles).forEach((file) => {
  compiler.fileTimestamps.set(file, +virtualFiles[file].stats.mtime);
});

still works for Webpack 4 in development mode and fixes rebuilds.

mode: 'development' crashes Webpack 3, but fix has no effect on it anyway.

Looks like Webpack 5 doesn't have compiler.fileTimestamps and we should look for other options.

I've disabled test for Webpack 3 and 5 until we find a solution.
Fix doesn't affect Webpack 3 and 5.

@non25 non25 marked this pull request as draft November 27, 2020 00:17
@non25 non25 changed the title Possible fix to reloading and rebuilding all virtual modules Fix rebuilding of all virtual modules on any change for webpack 4 Nov 27, 2020
@non25 non25 marked this pull request as ready for review November 27, 2020 16:59
Test and fix is skipped for webpack 3 and 5
@larixer larixer merged commit 95e79ab into sysgears:master Nov 27, 2020
@larixer
Copy link
Member

larixer commented Nov 27, 2020

Awesome, many thanks Kirill!

@larixer
Copy link
Member

larixer commented Nov 27, 2020

Published webpack-virtual-modules@0.4.1

@jquense
Copy link

jquense commented Dec 7, 2020

this change seems to break reloading for any file for webpack 5. I've been testing it locally, and rebuilds of the files still happen but they don't make it to the compilation, e.g. the file after the rebuild is still the old code.

@non25
Copy link
Contributor Author

non25 commented Dec 7, 2020

this change seems to break reloading for any file for webpack 5. I've been testing it locally, and rebuilds of the files still happen but they don't make it to the compilation, e.g. the file after the rebuild is still the old code.

So if you remove this code

const virtualFiles = (compiler as any).inputFileSystem._virtualFiles;
const fts = compiler.fileTimestamps as any;
if (virtualFiles && fts && typeof fts.set === 'function') {
Object.keys(virtualFiles).forEach((file) => {
fts.set(file, +virtualFiles[file].stats.mtime);
});
}

it starts to work normally?

Webpack 5 doesn't have compiler.fileTimestamps, so condition in this code won't pass. You can try to console.log from it to confirm, but I'm quite positive that it shouldn't affect webpack 3 and 5 at all.

@jquense
Copy link

jquense commented Dec 7, 2020

Webpack 5 doesn't have compiler.fileTimestamps

I'm not seeing that, it's not supposed to have it but it does exist for back compat:
image

at least ion 5.1.3. guarding here using webpack.version fixed it for me

@non25
Copy link
Contributor Author

non25 commented Dec 7, 2020

Can you make reproduction repo ?
Can't reproduce the problem with webpack 5.3 and webpack 5.10.
https://github.com/non25/webpack-virtual-modules/tree/repro-no-rebuilds

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

Successfully merging this pull request may close these issues.

None yet

3 participants