-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix Webpack production mode compatibility #6956
Conversation
I must also mention that an alternative way to achieve a working Webpack build would be to release new versions of |
@mourner can you explain the relationship between |
@anandthakker sure. If you look into var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; When Rollup encounters a commonjs-style UMD build such as previous versions of var index_umd = createCommonjsModule(function (module, exports) {
(function (global, factory) {
'object' === 'object' && 'object' !== 'undefined' ? module.exports = factory() :
typeof undefined === 'function' && undefined.amd ? undefined(factory) :
(global.ShelfPack = factory());
}(commonjsGlobal, (function () { Setting |
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.
Good find! As I recall, the typeof global
check was buried much deeper in a transitive dependency with browserify, so it seems that switching to rollup had yet another benefit.
build/rollup_plugins.js
Outdated
@@ -29,6 +29,7 @@ export const plugins = () => [ | |||
include: 'src/shaders/index.js' | |||
}), | |||
commonjs({ | |||
ignoreGlobal: true, |
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 a comment here outlining why we're using this option and linking to this PR.
477d170
to
01213e8
Compare
Could you please tell, is this PR included in latest npm release (0.47.0-beta.1), if not is there any tentative date planned for next release including this PR. It would be really helpful if you can provide some info regarding the same. Thanks. |
It's not included in 0.47.0-beta.1, but if some of the folks here who have been affected by the issue can try it out (using a build from |
@jfirebaugh @mourner Just tried it with my current project, LGTM 👍 |
A proposal for fixing #4359. Sets
ignoreGlobal: true
option forrollup-plugin-commonjs
plugin, turning off its handling of theglobal
keyword in CommonJS modules, and upgrades the plugin to the latest version (because the option didn't work properly in the previous one). In particular, it stops transforming top-levelthis
reference into a variable that contains thetypeof global
check (which consequently triggered Webpack issues).One consequence of the fix is that GL JS will throw a runtime error when it encounters a reference to the
global
keyword. However, there are no such instances in the bundle currently — the only real reference I found (in the browserified nodeassert
module) gets treeshaken away because it's in unused methods. So in theory this fix won't bring much trouble unless we plan on using Node-targeted modules with theglobal
keyword in future.Thanks a lot to @Aendrew who provided a minimal repro that helped me find this fix.