UNPKG

tsup

Version:

Bundle your TypeScript library with no config, powered by esbuild

14 lines (11 loc) 569 B
// Shim globals in cjs bundle // There's a weird bug that esbuild will always inject importMetaUrl // if we export it as `const importMetaUrl = ... __filename ...` // But using a function will not cause this issue const getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') ? document.currentScript.src : new URL("main.js", document.baseURI).href; export const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()