-
Notifications
You must be signed in to change notification settings - Fork 109
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
Chunk file output not deterministic #478
Comments
Yes, this seems like a good thing to take care of in the defaults settings. I suspect it's optimization.moduleIds that needs to be set to Could you try that out and PR it into our defaults if it solves the problem? Thanks. |
Thanks @ef4 ! So I added:
...however it doesn't change the behavior unfortunately. Are those integers indeed "module ids", or are they something else? |
They look like moduleIds to me, but I could be wrong. Double check that your setting is really getting through to webpack. Maybe some other bug is preventing it from getting merged into the webpack config correctly. If you change this setting and diff the output from before, does anything change? Something should if the setting is having any effect. |
@ef4 Thanks heaps for the guidance. I enabled debug mode for It seems clear that the option is passed through to webpack based on this, but indeed, nothing else changes regardless of whether I have this option set or not. That is, these module ids always differ from one build to the next, regardless of the option, but no other asset files change (app- and vendor- files are unchanged as expected, even if I compare them across one build with the option enabled and one build without). I guess I'll start looking into ways to enable debug logs on webpack. If you have any other ideas, let me know! |
Interestingly, changing the option to something else like |
Ok, getting closer here. I noticed when using the "named" option that the module names themselves change every build, based on what looks like broccoli behavior: Based on the webpack docs, deterministic module ids are based on hashing the module name, so if the module name isn't deterministic then determinism is obviously lost. Will now start digging to see if the broccoli names can be made deterministic. |
So using the "size" option, i.e.
...solves this issue in the sense that the multiple successive builds of the same unchanged source files give the same output files. I don't think this approach offers the same "long term caching" benefits of the "deterministic" option documented by webpack, but for my use-case the problem is solved (I just needed repeat builds to be deterministic). @ef4 What do you think...is "size" a suitable default in order to resolve the issue (if so, I can create a PR), or do you perhaps know how to make the broccoli-style module names from my screenshot above deterministic so the "deterministic" webpack option could work? |
Nice investigating, this is important:
I think that's what we should fix. It's true that if we let broccoli pick the temp directory it will be non-deterministic. But we don't have to let it pick, we can make our own. For the same reason, Embroider generates a stable tempdir per project, and that's what it shows to webpack. |
@ef4 Thanks heaps for the comments. I agree that it makes sense to resolve the core issue. I'm happy to spend time to make a contribution, but after taking browsing this repo, the broccoli repo and the Embroider repo, I'm struggling to find how to control which temp directory gets used. Could you perhaps point me in the right direction? |
I just thought of a possible alternative solution that might be better, which you could test. I don't think we currently set webpack's context. If we set it to the If that doesn't work, we can continue down the path of taking control of the tempdir name. This is where we set the directory:
Instead of using this broccoli-provided temp dir, we would make our own instead. It should get a stable name based off the app we're building, so that it's the same across rebuilds. Embroider does a similar thing here by hashing the filesystem path to the app that is being developed: |
@ef4 Yep bingo 👍 . Setting Setting I'll go ahead and create a PR... |
This commit works around a couple of issues in `ember-auto-import` which were causing non-deterministic chunk filenames and content. Deterministic output should improve cache-reusability across deploys. Refs: embroider-build/ember-auto-import#519 embroider-build/ember-auto-import#548 embroider-build/ember-auto-import#478
This commit works around a couple of issues in `ember-auto-import` which were causing non-deterministic chunk filenames and content. Deterministic output should improve cache-reusability across deploys. Refs: embroider-build/ember-auto-import#519 embroider-build/ember-auto-import#548 embroider-build/ember-auto-import#478
Repro steps (run on a Windows 10 with node 14.16.1):
npm install -g [email protected]
ember new ember-auto-import-chunk-demo
"ember-auto-import": "^2.2.4"
inpackage.json
"webpack": "^5.65.0"
topackage.json
npm install
ember build -prod
ember build -prod
again to see if the output indist
is deterministicExpected result: The chunk files in
dist
remain unchanged.Actual result: Some of the chunk files in
dist
have different content each time a build is done.The main culprit seems to be the chunk which is named
chunk.143
(at least that's how it's named on my machine). Every time a build happens, the integer ids change:The usual
app-
andvendor-
js files, as well as one of the chunk files, do indeed have a deterministic output.Is this expected? From the perspective of optimizing cache usage for end-user browsers, it seems sub-optimal.
If it is indeed unexpected, can it be fixed with a custom webpack config? I looked into the
deterministic
option for chunk ids in webpack, but it seems that should be default (and setting it explicitly didn't change the behavior).I'd be happy to investigate and prepare a contribution, however I could use a bit of a pointer in the correct direction from someone who's familiar with
The text was updated successfully, but these errors were encountered: