Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exclude entire import.meta.env object from content script output #1267

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions packages/wxt/src/client/content-scripts/custom-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
3 changes: 3 additions & 0 deletions packages/wxt/src/core/utils/building/import-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down