Skip to content

Commit

Permalink
fix: import.meta.url in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Mar 26, 2022
1 parent fedb106 commit 461ee0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/playground/worker/url-worker.js
@@ -1 +1 @@
self.postMessage('A string' + import.meta.env.BASE_URL)
self.postMessage('A string' + import.meta.env.BASE_URL + import.meta.url)
8 changes: 7 additions & 1 deletion packages/vite/src/node/plugins/define.ts
Expand Up @@ -10,6 +10,7 @@ const isNonJsRequest = (request: string): boolean => nonJsRe.test(request)

export function definePlugin(config: ResolvedConfig): Plugin {
const isBuild = config.command === 'build'
const isWorker = config.isWorker

const processNodeEnv: Record<string, string> = {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || config.mode),
Expand Down Expand Up @@ -62,7 +63,12 @@ export function definePlugin(config: ResolvedConfig): Plugin {
...(isNeedProcessEnv ? processNodeEnv : {}),
...userDefine,
...importMetaKeys,
...processEnv
...processEnv,
...(isWorker
? {
'import.meta.url': 'self.location.href'
}
: {})
}

const replacementsKeys = Object.keys(replacements)
Expand Down

0 comments on commit 461ee0c

Please sign in to comment.