Skip to content

Commit 712d83b

Browse files
authored
fix: correct import.meta.url shim (#218)
1 parent f5cbb89 commit 712d83b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

e2e/cases/shims/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('shims for import.meta.url in CJS', async () => {
2121
const { entries } = await buildAndGetResults(fixturePath);
2222
for (const shim of [
2323
`var __rslib_import_meta_url__ = /*#__PURE__*/ function() {
24-
'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
24+
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
2525
}();`,
2626
'console.log(__rslib_import_meta_url__);',
2727
]) {

packages/core/src/plugins/cjsShim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type RsbuildPlugin, rspack } from '@rsbuild/core';
22

33
const importMetaUrlShim = `var __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
4-
typeof document === 'undefined'
4+
return typeof document === 'undefined'
55
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
66
: (document.currentScript && document.currentScript.src) ||
77
new URL('main.js', document.baseURI).href;

0 commit comments

Comments
 (0)