Skip to content

Commit

Permalink
feat: rework more ssr.target webworker branches
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Apr 9, 2024
1 parent 7254175 commit 1f644d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
18 changes: 6 additions & 12 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,19 +662,9 @@ export async function buildEnvironment(
)
}

/**
* TODO:
* if (ssr.target === 'webworker') {
* build.rollupOptions.entryFileNames = '[name].js'
* build.rollupOptions.inlineDynamicImports = (typeof input === 'string' || Object.keys(input).length === 1))
* }
*/
const ssrNodeBuild = ssr && config.ssr.target === 'node'
const ssrWorkerBuild = ssr && config.ssr.target === 'webworker'

const format = output.format || 'es'
const jsExt =
ssrNodeBuild || libOptions
!environment.options.webCompatible || libOptions
? resolveOutputJsExtension(
format,
findNearestPackageData(config.root, config.packageCache)?.data
Expand Down Expand Up @@ -715,7 +705,11 @@ export async function buildEnvironment(
inlineDynamicImports:
output.format === 'umd' ||
output.format === 'iife' ||
(ssrWorkerBuild &&
// TODO: We need an abstraction for non-client environments?
// We should remove the explicit 'client' hcek here.
// Or maybe `inlineDynamicImports` should be an environment option?
(environment.name !== 'client' &&
environment.options.webCompatible &&
(typeof input === 'string' || Object.keys(input).length === 1)),
...output,
}
Expand Down
4 changes: 1 addition & 3 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,7 @@ async function prepareEsbuildOptimizerRun(
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || config.mode),
}

const ssr = environment.name !== 'client' // TODO:depsOptimizer
const platform =
ssr && config.ssr?.target !== 'webworker' ? 'node' : 'browser'
const platform = environment.options.webCompatible ? 'browser' : 'node'

const external = [...(optimizeDeps?.exclude ?? [])]

Expand Down

0 comments on commit 1f644d0

Please sign in to comment.