Skip to content

Set output.globalObject to this #7741

Closed
hchiam/create-react-app
#1
@kentcdodds

Description

@kentcdodds

When using workerize-loader, things work great (it's a fantastic tool), except that it does not work in dev mode. This is because HotModuleReplacement gets loaded into the webworker and the HMR file references window.

Describe the solution you'd like

I'd like to have the webpack configuration set output.globalObject to 'this'. The default is 'window'. Changing it to 'this' will have no negative impact on existing or future users, and it will allow people to begin using workerize-loader without ejecting.

Describe alternatives you've considered

You can manually modify the configuration in node_modules (and just remember to do that anytime you re-install deps). Or you can eject.

Additional context

Before:

image

After:

image

This code is generated from this template:

https://github.com/webpack/webpack/blob/ba20513223607eaccb615c8ffabe824413b1613c/lib/web/JsonpMainTemplatePlugin.js#L603-L606

Activity

added a commit that references this issue on Sep 26, 2019
4ff4824
kentcdodds

kentcdodds commented on Sep 26, 2019

@kentcdodds
ContributorAuthor

Made a PR for this: #7742. It's a simple change with no downside and plenty of upside :)

iansu

iansu commented on Sep 26, 2019

@iansu
Contributor

Do you not have to eject to use workerize-loader?

kentcdodds

kentcdodds commented on Sep 26, 2019

@kentcdodds
ContributorAuthor

Nope :) Just use the loader import syntax (as documented in the workerize-loader docs) and it works (you do have to disable the lint rule for that to work, but it's not like you do this in many places in the app so it's NBD).

added a commit that references this issue on Sep 26, 2019
42ee721
locked and limited conversation to collaborators on Oct 1, 2019
added a commit that references this issue on Nov 21, 2019
f1138a4
added a commit that references this issue on Jan 3, 2020
d4d5df6

8 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @iansu@kentcdodds

      Issue actions

        Set output.globalObject to `this` · Issue #7741 · facebook/create-react-app