@@ -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,61 @@ 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+ let libCssFilename : string | undefined
557+ if ( env . config . build . lib ) {
558+ const libOptions = env . config . build . lib
559+ if ( typeof libOptions . cssFileName === 'string' ) {
560+ libCssFilename = `${ libOptions . cssFileName } .css`
561+ } else if ( typeof libOptions . fileName === 'string' ) {
562+ libCssFilename = `${ libOptions . fileName } .css`
563+ }
564+ }
565+ return [
566+ {
567+ name : 'native:css-post-compat' ,
568+ ...( config . isOutputOptionsForLegacyChunks
569+ ? {
570+ renderChunk ( _ , __ , opts ) {
571+ const isLegacy =
572+ env . config . isOutputOptionsForLegacyChunks ?.( opts ) ?? false
573+ if ( isLegacy ) {
574+ isLegacySet . add ( env . name )
575+ } else {
576+ isLegacySet . delete ( env . name )
577+ }
578+ } ,
579+ }
580+ : { } ) ,
581+ } ,
582+ viteCSSPostPlugin ( {
583+ root : env . config . root ,
584+ isLib : ! ! env . config . build . lib ,
585+ isSsr : ! ! env . config . build . ssr ,
586+ isWorker : env . config . isWorker ,
587+ isLegacy : env . config . isOutputOptionsForLegacyChunks
588+ ? ( ) => isLegacySet . has ( env . name )
589+ : undefined ,
590+ isClient : env . config . consumer === 'client' ,
591+ cssCodeSplit : env . config . build . cssCodeSplit ,
592+ sourcemap : ! ! env . config . build . sourcemap ,
593+ assetsDir : env . config . build . assetsDir ,
594+ urlBase : env . config . base ,
595+ decodedBase : env . config . decodedBase ,
596+ libCssFilename,
597+ cssMinify : env . config . build . cssMinify
598+ ? async ( content , inline ) => {
599+ return await minifyCSS ( content , env . config , inline )
600+ }
601+ : undefined ,
602+ renderBuiltUrl : env . config . experimental . renderBuiltUrl ,
603+ } ) ,
604+ ]
605+ } )
606+ }
607+
509608 return {
510609 name : 'vite:css-post' ,
511610
0 commit comments