@@ -27,6 +27,7 @@ import type {
2727 TransformAttributeResult as LightningCssTransformAttributeResult ,
2828 TransformResult as LightningCssTransformResult ,
2929} from 'lightningcss'
30+ import { viteCSSPlugin , viteCSSPostPlugin } from 'rolldown/experimental'
3031import type { LightningCSSOptions } from '#types/internal/lightningcssOptions'
3132import type {
3233 LessPreprocessorBaseOptions ,
@@ -89,7 +90,7 @@ import type { ResolveIdFn } from '../idResolver'
8990import { PartialEnvironment } from '../baseEnvironment'
9091import type { TransformPluginContext } from '../server/pluginContainer'
9192import { searchForWorkspaceRoot } from '../server/searchRoot'
92- import { type DevEnvironment } from '..'
93+ import { type DevEnvironment , perEnvironmentPlugin } from '..'
9394import type { PackageCache } from '../packages'
9495import { findNearestMainPackageData } from '../packages'
9596import { nodeResolveWithVite } from '../nodeResolve'
@@ -311,6 +312,49 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
311312 } )
312313 }
313314
315+ if ( isBuild && config . nativePluginEnabledLevel >= 1 ) {
316+ return perEnvironmentPlugin ( 'vite:native-css' , ( env ) => {
317+ return [
318+ {
319+ name : 'vite:css-compat' ,
320+ buildStart ( ) {
321+ preprocessorWorkerController = createPreprocessorWorkerController (
322+ normalizeMaxWorkers ( config . css . preprocessorMaxWorkers ) ,
323+ )
324+ preprocessorWorkerControllerCache . set (
325+ config ,
326+ preprocessorWorkerController ,
327+ )
328+ } ,
329+
330+ buildEnd ( ) {
331+ preprocessorWorkerController ?. close ( )
332+ } ,
333+ } ,
334+ viteCSSPlugin ( {
335+ root : env . config . root ,
336+ isLib : ! ! env . config . build . lib ,
337+ publicDir : env . config . publicDir ,
338+ async compileCSS ( url , importer , resolver ) {
339+ return compileCSS (
340+ env ,
341+ url ,
342+ importer ,
343+ preprocessorWorkerController ! ,
344+ ( url , importer ) => {
345+ return resolver . call ( url , importer )
346+ } ,
347+ )
348+ } ,
349+ resolveUrl ( url , importer ) {
350+ return idResolver ( env , url , importer )
351+ } ,
352+ assetInlineLimit : env . config . build . assetsInlineLimit ,
353+ } ) ,
354+ ]
355+ } )
356+ }
357+
314358 return {
315359 name : 'vite:css' ,
316360
@@ -506,6 +550,46 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
506550 return cssBundleName
507551 }
508552
553+ if ( config . command === 'build' && config . nativePluginEnabledLevel >= 1 ) {
554+ const isLegacySet = new Set < string > ( )
555+ return perEnvironmentPlugin ( 'native:css-post' , ( env ) => {
556+ return [
557+ {
558+ name : 'native:css-post-compat' ,
559+ ...( config . isOutputOptionsForLegacyChunks
560+ ? {
561+ renderChunk ( _ , __ , opts ) {
562+ const isLegacy =
563+ env . config . isOutputOptionsForLegacyChunks ?.( opts ) ?? false
564+ if ( isLegacy ) {
565+ isLegacySet . add ( env . name )
566+ } else {
567+ isLegacySet . delete ( env . name )
568+ }
569+ } ,
570+ }
571+ : { } ) ,
572+ } ,
573+ viteCSSPostPlugin ( {
574+ root : env . config . root ,
575+ isLib : ! ! env . config . build . lib ,
576+ isSsr : ! ! env . config . build . ssr ,
577+ isWorker : env . config . isWorker ,
578+ isLegacy : env . config . isOutputOptionsForLegacyChunks
579+ ? ( ) => isLegacySet . has ( env . name )
580+ : undefined ,
581+ isClient : env . config . consumer === 'client' ,
582+ cssCodeSplit : env . config . build . cssCodeSplit ,
583+ sourcemap : ! ! env . config . build . sourcemap ,
584+ assetsDir : env . config . build . assetsDir ,
585+ urlBase : env . config . base ,
586+ decodedBase : env . config . decodedBase ,
587+ renderBuiltUrl : env . config . experimental . renderBuiltUrl ,
588+ } ) ,
589+ ]
590+ } )
591+ }
592+
509593 return {
510594 name : 'vite:css-post' ,
511595
0 commit comments