You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: support import.meta.env in worker URL template literals
Allows template literals containing only import.meta.env.* expressions
in Web Worker URL definitions, transforming them to string concatenation.
Before (blocked with error):
```javascript
const worker = new Worker(
new URL(\`./path/\${import.meta.env.MY_VAR}/worker.ts\`, import.meta.url),
{ type: 'module' }
)
```
After (now supported):
The template literal is automatically transformed to:
```javascript
new URL('./path/' + import.meta.env.MY_VAR + '/worker.ts', import.meta.url)
```
Implementation:
- Added transformSafeTemplateLiteral() to detect and transform safe templates
- Only allows import.meta.env.* expressions (no other dynamic variables)
- Transforms safe templates to string concatenation before Rollup processing
- Provides helpful error messages for truly dynamic expressions
- Added test files demonstrating the feature
Technical details:
- Two-pass transform: first transforms safe templates, then processes workers
- Uses AST parsing to validate only safe expressions are present
- Preserves source maps through MagicString transformations
- No new dependencies required
0 commit comments