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

build: compile 4 webpackRendererConfigs instead of N #3101

Merged
merged 22 commits into from
Aug 30, 2023

Conversation

georgexu99
Copy link
Contributor

Co-authored-by: Samuel Attard marshallofsound@electronjs.org
Co-authored-by: Keeley Hammond vertedinde@electronjs.org

related issue:
#3087

getRendererConfig currently returns a separate config per entryPoint: this build speed regression was introduced in 1f45e2c when each entryPoint gained the capability to set its own nodeIntegration

This change routes each entry point into one of 4 buckets such that only 4 configs are generated.

Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackPlugin.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackPlugin.ts Outdated Show resolved Hide resolved
@georgexu99
Copy link
Contributor Author

@MarshallOfSound
https://github.com/electron/forge/pull/3101/files/9830b8646cbfe857d9649ed2b673b6a04ca6e94d#r1036759743
addressed all comments minus this one, wasn't too sure what you meant. lines 198, 207 are angry- did you want to create a new target?

lines 250, 277, created a new guard function to assert type let me know if that was not the move

@georgexu99 georgexu99 marked this pull request as ready for review December 13, 2022 18:40
@georgexu99 georgexu99 requested a review from a team December 13, 2022 18:40
@georgexu99
Copy link
Contributor Author

Currently potentially having issue w/ asset relocator patch for the failing tests :( path/to/x is not being shortened to _dirname

@georgexu99 georgexu99 requested a review from a team as a code owner January 31, 2023 00:08
@erickzhao erickzhao marked this pull request as draft February 7, 2023 00:34
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/WebpackConfig.ts Outdated Show resolved Hide resolved
packages/plugin/webpack/src/util/rendererTypeUtils.ts Outdated Show resolved Hide resolved
jsPath: path.join(rendererOut, 'main_window/preload.js'),
nativeModulesString: '.ab=__dirname+"/native_modules/"',
nativeModulesString: '.ab=require("path").resolve(require("path").dirname(__filename),"..")+"/native_modules/"',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you figure out what generates this path? This could probably be resolve(__dirname, '..') instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test, we generate the path in injectedProductionDirnameCode() within AssetRelocatorPatch.ts

@georgexu99 georgexu99 marked this pull request as ready for review March 13, 2023 17:21
@kyleshay
Copy link

kyleshay commented May 9, 2023

Gentle bump @MarshallOfSound — I tried building forge from this commit and was going to test it against my steps from this comment: #3087 (comment) to validate the change, but was running into an issue with linking, I think.

@erickzhao erickzhao requested a review from a team June 15, 2023 21:19
@@ -275,7 +275,7 @@ export default class WebpackConfigGenerator {
);
}
}
return webpackMerge(baseConfig, rendererConfig || {}, { entry, output, plugins });
return webpackMerge({ entry, output, plugins }, rendererConfig || {}, baseConfig);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webpack Merge prioritizes right -> left:

we determine the config target within the baseConfig (i.e 'web', 'electron-preload') and not the one generated from rendererConfig = this.pluginConfig.renderer.config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: maybe I was wrong and shouldn't have touched this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgexu99 Could you link where you saw the prioritization of merging? I don't see that in the webpack docs - I'd err on the side of leaving is as it was unless we're seeing a specific benefit from it 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://yarnpkg.com/package?name=webpack-merge#:~:text=webpack%2Dmerge%20provides%20a%20merge,values%20within%20a%20function%20again.

within the first code example, a comment mentions that keys to the right take precedence.
I think these need to be moved because otherwise, the separate targets that this PR evaluates do not get translated into the final webpack config (ex. prior to this change, target: electron-preload target in the baseconfig gets overwritten by target: web in the rendererConfig, even if its a preload-only entrypoint

I'm gonna dig a bit deeper and test whether I can make a functioning webpack app with these changes

Copy link
Member

@VerteDinde VerteDinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on the condition that we document or revert the webpack merge change above - excited to have this in!

@georgexu99 georgexu99 force-pushed the gxu-build-speed-regression branch from fcef7f9 to d290067 Compare August 30, 2023 19:04
@georgexu99 georgexu99 enabled auto-merge (squash) August 30, 2023 22:29
@georgexu99 georgexu99 disabled auto-merge August 30, 2023 22:34
@georgexu99 georgexu99 merged commit ed45e79 into main Aug 30, 2023
3 checks passed
@georgexu99 georgexu99 deleted the gxu-build-speed-regression branch August 30, 2023 23:00
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.

5 participants