File tree 3 files changed +18
-6
lines changed
packages/vite/src/node/plugins
3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -165,10 +165,21 @@ export async function workerFileToUrl(
165
165
export function webWorkerPostPlugin ( ) : Plugin {
166
166
return {
167
167
name : 'vite:worker-post' ,
168
- resolveImportMeta ( property , { chunkId , format } ) {
168
+ resolveImportMeta ( property , { format } ) {
169
169
// document is undefined in the worker, so we need to avoid it in iife
170
- if ( property === 'url' && format === 'iife' ) {
171
- return 'self.location.href'
170
+ if ( format === 'iife' ) {
171
+ // compiling import.meta
172
+ if ( ! property ) {
173
+ // rollup only supports `url` property. we only support `url` property as well.
174
+ // https://github.com/rollup/rollup/blob/62b648e1cc6a1f00260bb85aa2050097bb4afd2b/src/ast/nodes/MetaProperty.ts#L164-L173
175
+ return `{
176
+ url: self.location.href
177
+ }`
178
+ }
179
+ // compiling import.meta.url
180
+ if ( property === 'url' ) {
181
+ return 'self.location.href'
182
+ }
172
183
}
173
184
174
185
return null
Original file line number Diff line number Diff line change @@ -114,17 +114,17 @@ describe.runIf(isBuild)('build', () => {
114
114
test ( 'module worker' , async ( ) => {
115
115
await untilUpdated (
116
116
async ( ) => page . textContent ( '.worker-import-meta-url' ) ,
117
- / A \s s t r i n g .* \/ i i f e \/ .+ u r l - w o r k e r \. j s / ,
117
+ / A \s s t r i n g .* \/ i i f e \/ .+ u r l - w o r k e r \. j s . + u r l - w o r k e r \. j s / ,
118
118
true ,
119
119
)
120
120
await untilUpdated (
121
121
( ) => page . textContent ( '.worker-import-meta-url-resolve' ) ,
122
- / A \s s t r i n g .* \/ i i f e \/ .+ u r l - w o r k e r \. j s / ,
122
+ / A \s s t r i n g .* \/ i i f e \/ .+ u r l - w o r k e r \. j s . + u r l - w o r k e r \. j s / ,
123
123
true ,
124
124
)
125
125
await untilUpdated (
126
126
( ) => page . textContent ( '.worker-import-meta-url-without-extension' ) ,
127
- 'A string' ,
127
+ / A \s s t r i n g . * \/ i i f e \/ . + u r l - w o r k e r \. j s . + u r l - w o r k e r \. j s / ,
128
128
true ,
129
129
)
130
130
await untilUpdated (
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ self.postMessage(
3
3
'A string' ,
4
4
import . meta. env . BASE_URL ,
5
5
self . location . url ,
6
+ import . meta && import . meta. url ,
6
7
import . meta. url ,
7
8
] . join ( ' ' ) ,
8
9
)
You can’t perform that action at this time.
0 commit comments