MCPcopy
hub / github.com/vitejs/vite / getRolldownOptions

Method getRolldownOptions

packages/vite/src/node/server/bundledDev.ts:344–408  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

342 }
343
344 private async getRolldownOptions() {
345 const chunkMetadataMap = new ChunkMetadataMap()
346 const rolldownOptions = resolveRolldownOptions(
347 this.environment,
348 chunkMetadataMap,
349 )
350 rolldownOptions.experimental ??= {}
351 rolldownOptions.experimental.devMode = {
352 lazy: true,
353 ...(typeof rolldownOptions.experimental.devMode === 'object'
354 ? rolldownOptions.experimental.devMode
355 : {}),
356 implement: await getHmrImplementation(
357 this.environment.getTopLevelConfig(),
358 ),
359 }
360
361 // disable inlineConst optimization due to a bug in Rolldown
362 // https://github.com/vitejs/vite/issues/21843
363 rolldownOptions.optimization ??= {}
364 rolldownOptions.optimization.inlineConst = false
365
366 // In bundledDev mode, Rolldown's DevEngine generates lazy-loading stub modules
367 // for dynamically imported files, appending `?rolldown-lazy=1` to the module ID.
368 // Skip all plugins for these stub modules as a workaround.
369 // https://github.com/vitejs/vite/issues/22651
370 const plugins = await asyncFlatten([rolldownOptions.plugins])
371 for (const plugin of plugins) {
372 const transform =
373 plugin && 'transform' in plugin ? plugin.transform : undefined
374 if (!transform) continue
375 const handler =
376 typeof transform === 'function' ? transform : transform.handler
377 const wrappedHandler: typeof handler = function (this, code, id, opts) {
378 if (id.includes('?rolldown-lazy=')) return null
379 return handler.call(this, code, id, opts)
380 }
381 if (typeof transform === 'function') {
382 ;(plugin as any).transform = wrappedHandler
383 } else {
384 transform.handler = wrappedHandler
385 }
386 }
387 rolldownOptions.plugins = plugins
388
389 // set filenames to make output paths predictable so that `renderChunk` hook does not need to be used
390 if (Array.isArray(rolldownOptions.output)) {
391 for (const output of rolldownOptions.output) {
392 output.entryFileNames = 'assets/[name].js'
393 output.chunkFileNames = 'assets/[name]-[hash].js'
394 output.assetFileNames = 'assets/[name]-[hash][extname]'
395 output.minify = false
396 output.sourcemap = true
397 }
398 } else {
399 rolldownOptions.output ??= {}
400 rolldownOptions.output.entryFileNames = 'assets/[name].js'
401 rolldownOptions.output.chunkFileNames = 'assets/[name]-[hash].js'

Callers 1

listenMethod · 0.95

Calls 4

resolveRolldownOptionsFunction · 0.90
getHmrImplementationFunction · 0.90
asyncFlattenFunction · 0.90
getTopLevelConfigMethod · 0.80

Tested by

no test coverage detected