diff --git a/packages/wxt/src/client/content-scripts/custom-events.ts b/packages/wxt/src/client/content-scripts/custom-events.ts index 8b14a1b83..08ca87a26 100644 --- a/packages/wxt/src/client/content-scripts/custom-events.ts +++ b/packages/wxt/src/client/content-scripts/custom-events.ts @@ -15,12 +15,5 @@ export class WxtLocationChangeEvent extends Event { * Returns an event name unique to the extension and content script that's running. */ export function getUniqueEventName(eventName: string): string { - // During the build process, import.meta.env is not defined when importing - // entrypoints to get their metadata. - const entrypointName = - typeof import.meta.env === 'undefined' - ? 'build' - : import.meta.env.ENTRYPOINT; - - return `${browser?.runtime?.id}:${entrypointName}:${eventName}`; + return `${browser?.runtime?.id}:${import.meta.env.ENTRYPOINT}:${eventName}`; } diff --git a/packages/wxt/src/core/utils/building/import-entrypoint.ts b/packages/wxt/src/core/utils/building/import-entrypoint.ts index 4bfde90cc..d2a029f4d 100644 --- a/packages/wxt/src/core/utils/building/import-entrypoint.ts +++ b/packages/wxt/src/core/utils/building/import-entrypoint.ts @@ -112,6 +112,9 @@ function getEsbuildOptions(opts: JitiTransformOptions): TransformOptions { return { format: 'cjs', loader: isJsx ? 'tsx' : 'ts', + define: { + 'import.meta.env.ENTRYPOINT': '"build"', + }, ...(isJsx ? { // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while