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

shim "this" reference in playground #5277

Merged
merged 1 commit into from
Jan 29, 2021
Merged

shim "this" reference in playground #5277

merged 1 commit into from
Jan 29, 2021

Conversation

patrickkettner
Copy link
Collaborator

fixes #5272, not sure how to fully test the playground, however

Copy link
Collaborator

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

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

I don't understand what this does, but I trust you. Do you know whether this affects bundle size?

@@ -1,4 +1,5 @@
const path = require('path');
const webpack = require('webpack');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add webpack, in order to call webpack.DefinePlugin

@@ -20,6 +21,9 @@ module.exports = (env, argv) => {
sourceMapFilename: '[name].map',
publicPath: '',
},
node: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

webpack node configuration

@@ -20,6 +21,9 @@ module.exports = (env, argv) => {
sourceMapFilename: '[name].map',
publicPath: '',
},
node: {
global: false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tell webpack to not include the polyfill

@@ -43,6 +47,9 @@ module.exports = (env, argv) => {
},
},
plugins: [
new webpack.DefinePlugin({
global: '(typeof globalThis ? globalThis : self)',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rather than use the polyfill that we are telling webpack to not use above, use this string of code.

When a module is trying to use global, webpack will regex in this string of code. if globalThis is defined, use it. If it is not defined, use self, since it is available in worker and DOM, and is a shorter string than "window".

@patrickkettner
Copy link
Collaborator Author

I added comments inline, but here is a diff

image

It is a 0.061% filesize (680b in 1.1MB file) increase

@sebastianbenz
Copy link
Collaborator

Thanks for explaining!

@patrickkettner patrickkettner merged commit 9edb6d3 into future Jan 29, 2021
@patrickkettner patrickkettner deleted the dontGlobalThis branch January 29, 2021 15:48
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.

CSP Errors on homepage
2 participants