diff --git a/packages/bundler-webpack/src/plugins/RuntimePublicPathPlugin.ts b/packages/bundler-webpack/src/plugins/RuntimePublicPathPlugin.ts index 6d339d83dc57..19004a0e3b7e 100644 --- a/packages/bundler-webpack/src/plugins/RuntimePublicPathPlugin.ts +++ b/packages/bundler-webpack/src/plugins/RuntimePublicPathPlugin.ts @@ -24,23 +24,9 @@ export class RuntimePublicPathPlugin { ) return; // @ts-ignore - module._cachedGeneratedCode = `__webpack_require__.p = (function(){ -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis -function __check(it) { - return it && it.Math === Math && it; -}; - -var __global =( - __check(typeof globalThis == 'object' && globalThis) || - __check(typeof window == 'object' && window) || - __check(typeof self == 'object' && self) -); - -if(__global && __global.publicPath) return __global.publicPath; - -// fix: https://github.com/umijs/umi/issues/12781 -return ${JSON.stringify(compilation.outputOptions.publicPath || '/')}; -})();`; + module._cachedGeneratedCode = `__webpack_require__.p = (typeof globalThis !== 'undefined' ? globalThis : window).publicPath || ${ + compilation.outputOptions.publicPath ?? '/' + };`; } }, );