@@ -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,48 @@ 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+ isLib : ! ! env . config . build . lib ,
336+ publicDir : env . config . publicDir ,
337+ async compileCSS ( url , importer , resolver ) {
338+ return compileCSS (
339+ env ,
340+ url ,
341+ importer ,
342+ preprocessorWorkerController ! ,
343+ ( url , importer ) => {
344+ return resolver . call ( url , importer )
345+ } ,
346+ )
347+ } ,
348+ resolveUrl ( url , importer ) {
349+ return idResolver ( env , url , importer )
350+ } ,
351+ assetInlineLimit : env . config . build . assetsInlineLimit ,
352+ } ) ,
353+ ]
354+ } )
355+ }
356+
314357 return {
315358 name : 'vite:css' ,
316359
@@ -506,6 +549,45 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
506549 return cssBundleName
507550 }
508551
552+ if ( config . command === 'build' && config . nativePluginEnabledLevel >= 1 ) {
553+ const isLegacySet = new Set < string > ( )
554+ return perEnvironmentPlugin ( 'native:css-post' , ( env ) => {
555+ return [
556+ {
557+ name : 'native:css-post-compat' ,
558+ ...( config . isOutputOptionsForLegacyChunks
559+ ? {
560+ renderChunk ( _ , __ , opts ) {
561+ const isLegacy =
562+ env . config . isOutputOptionsForLegacyChunks ?.( opts ) ?? false
563+ if ( isLegacy ) {
564+ isLegacySet . add ( env . name )
565+ } else {
566+ isLegacySet . delete ( env . name )
567+ }
568+ } ,
569+ }
570+ : { } ) ,
571+ } ,
572+ viteCSSPostPlugin ( {
573+ isLib : ! ! env . config . build . lib ,
574+ isSsr : ! ! env . config . build . ssr ,
575+ isWorker : env . config . isWorker ,
576+ isLegacy : env . config . isOutputOptionsForLegacyChunks
577+ ? ( ) => isLegacySet . has ( env . name )
578+ : undefined ,
579+ isClient : env . config . consumer === 'client' ,
580+ cssCodeSplit : env . config . build . cssCodeSplit ,
581+ sourcemap : ! ! env . config . build . sourcemap ,
582+ assetsDir : env . config . build . assetsDir ,
583+ urlBase : env . config . base ,
584+ decodedBase : env . config . decodedBase ,
585+ renderBuiltUrl : env . config . experimental . renderBuiltUrl ,
586+ } ) ,
587+ ]
588+ } )
589+ }
590+
509591 return {
510592 name : 'vite:css-post' ,
511593
0 commit comments