refactor globalThis polyfill to improve legacy support

This commit is contained in:
Nacho Codoñer
2025-11-20 09:52:46 +01:00
parent f628e5cf93
commit 391672008d

View File

@@ -443,13 +443,18 @@ class RequireExternalsPlugin {
_ensureGlobalThisModule() {
const block = [
`/* Polyfill globalThis.module & exports */`,
`if (typeof globalThis.module === 'undefined') {`,
` globalThis.module = { exports: {} };`,
`/* Polyfill globalThis.module, exports & module for legacy */`,
`if (typeof globalThis !== 'undefined') {`,
` if (typeof globalThis.module === 'undefined') {`,
` globalThis.module = { exports: {} };`,
` }`,
` if (typeof globalThis.exports === 'undefined') {`,
` globalThis.exports = globalThis.module.exports;`,
` }`,
`}`,
`if (typeof window.module === 'undefined') {`,
` window.module = { exports: {} };`,
`}`,
`if (typeof globalThis.exports === 'undefined') {`,
` globalThis.exports = globalThis.module.exports;`,
`}`
].join('\n') + '\n';
let content = '';