Skip to content

Commit

Permalink
fix: invalid import.meta.url when build (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jun 7, 2024
1 parent ff82786 commit e776afa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/vite-plugin-monkey/src/client/window.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { MonkeyWindow } from './types';
import type { MonkeyWindow } from './types';

const key =
`__monkeyWindow-` + new URL(import.meta.url || location.href).origin;
`__monkeyWindow-` +
(() => {
try {
return new URL(import.meta.url).origin;
} catch {
return location.origin;
}
})();

// @ts-ignore
export const monkeyWindow: MonkeyWindow = document[key] ?? window;

0 comments on commit e776afa

Please sign in to comment.