Skip to content

Commit

Permalink
fix(plugin-legacy): fix legacy plugin not working in worker context
Browse files Browse the repository at this point in the history
  • Loading branch information
sapenlei committed Jan 8, 2025
1 parent f7b1964 commit 88540b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
),
)
}
if (config.isWorker) {
config.logger.warn(
colors.yellow(
`Workers are not supported when generating legacy chunks. Ensure that workers are not used in your application when targeting legacy browsers.`,
),
)
}
},
}

Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ export const buildEsbuildPlugin = (): Plugin => {
return null
}

if (chunk.name === 'worker' && opts.format === 'iife') {
options.format = 'iife'
}

const res = await transformWithEsbuild(
code,
chunk.fileName,
Expand Down

0 comments on commit 88540b1

Please sign in to comment.