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

allow to override worker public path #2747

Merged
merged 1 commit into from
Apr 3, 2024
Merged

allow to override worker public path #2747

merged 1 commit into from
Apr 3, 2024

Conversation

robin-drexler
Copy link
Member

@robin-drexler robin-drexler commented Apr 2, 2024

Description

Allows to override __worker_public_path__ with a plugin option. This is needed for using a custom Extension sandbox URL while not changing other URLs in webpack's build (example).

@@ -137,7 +137,9 @@ export function pitch(this: LoaderContext<Options>, request: string) {

return callback!(
null,
`export default __webpack_public_path__ + ${JSON.stringify(entry)};`,
`export default (typeof __worker_public_path__ != "undefined" ? __worker_public_path__ : __webpack_public_path__) + ${JSON.stringify(
Copy link
Member Author

Choose a reason for hiding this comment

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

__webpack_public_path__ is guaranteed to exist, but __worker_public_path__ isn't, so we need to check if it exists before accessing it.

Copy link

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

🎩 This is working for me. Variable configuration adds flexibility to web workers so the build system can continue using __webpack_public_path__ in other places, undisturbed.

@@ -12,6 +12,7 @@ const moduleWrapperCache = new Map<string, string | false>();
export interface Options {
name?: string;
wrapperModule?: string;
magicGlobalPathVariable?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking on the name: maybe publicPathGlobal/ publicPathGlobalVariable? There isn’t necessarily any magic going on here, it can be any valid JS expression that will resolve to a string at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed it to publicPathGlobalVariable

@robin-drexler robin-drexler marked this pull request as ready for review April 3, 2024 15:17
@robin-drexler robin-drexler requested a review from a team as a code owner April 3, 2024 15:17
@robin-drexler robin-drexler merged commit e2f380c into main Apr 3, 2024
9 checks passed
@robin-drexler robin-drexler deleted the rd/worker-path branch April 3, 2024 15:23
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

4 participants