-
Notifications
You must be signed in to change notification settings - Fork 695
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
Conversation
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)', |
There was a problem hiding this comment.
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".
I added comments inline, but here is a diff It is a 0.061% filesize (680b in 1.1MB file) increase |
Thanks for explaining! |
fixes #5272, not sure how to fully test the playground, however