@@ -38,7 +38,7 @@ import type {
3838} from 'lightningcss'
3939import type { CustomPluginOptionsVite } from 'types/metadata'
4040import type { EsbuildTransformOptions } from 'types/internal/esbuildOptions'
41- import { getCodeWithSourcemap , injectSourcesContent } from '../server/sourcemap'
41+ // import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
4242import type { EnvironmentModuleNode } from '../server/moduleGraph'
4343import {
4444 createToImportMetaURLBasedRelativeRuntime ,
@@ -48,7 +48,7 @@ import {
4848} from '../build'
4949import type { LibraryOptions } from '../build'
5050import {
51- CLIENT_PUBLIC_PATH ,
51+ // CLIENT_PUBLIC_PATH,
5252 CSS_LANGS_RE ,
5353 DEV_PROD_CONDITION ,
5454 ESBUILD_MODULES_TARGET ,
@@ -72,7 +72,7 @@ import {
7272 isDataUrl ,
7373 isExternalUrl ,
7474 isObject ,
75- joinUrlSegments ,
75+ // joinUrlSegments,
7676 mergeWithDefaults ,
7777 normalizePath ,
7878 processSrcSet ,
@@ -286,17 +286,17 @@ const postcssConfigCache = new WeakMap<
286286 PostCSSConfigResult | null | Promise < PostCSSConfigResult | null >
287287> ( )
288288
289- function encodePublicUrlsInCSS ( config : ResolvedConfig ) {
290- return config . command === 'build'
291- }
289+ // function encodePublicUrlsInCSS(config: ResolvedConfig) {
290+ // return config.command === 'build'
291+ // }
292292
293293const cssUrlAssetRE = / _ _ V I T E _ C S S _ U R L _ _ ( [ \d a - f ] + ) _ _ / g
294294
295295/**
296296 * Plugin applied before user plugins
297297 */
298298export function cssPlugin ( config : ResolvedConfig ) : Plugin {
299- const isBuild = config . command === 'build'
299+ // const isBuild = config.command === 'build'
300300 let moduleCache : Map < string , Record < string , string > >
301301
302302 const idResolver = createBackCompatIdResolver ( config , {
@@ -353,15 +353,15 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
353353
354354 // *.css?url
355355 // in dev, it's handled by assets plugin.
356- if ( isBuild ) {
356+ // if (isBuild) {
357357 id = injectQuery ( removeUrlQuery ( id ) , 'transform-only' )
358358 return (
359359 `import ${ JSON . stringify ( id ) } ;` +
360360 `export default "__VITE_CSS_URL__${ Buffer . from ( id ) . toString (
361361 'hex' ,
362362 ) } __"`
363363 )
364- }
364+ // }
365365 }
366366 } ,
367367 } ,
@@ -391,19 +391,19 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
391391 const urlResolver : CssUrlResolver = async ( url , importer ) => {
392392 const decodedUrl = decodeURI ( url )
393393 if ( checkPublicFile ( decodedUrl , config ) ) {
394- if ( encodePublicUrlsInCSS ( config ) ) {
394+ // if (encodePublicUrlsInCSS(config)) {
395395 return [ publicFileToBuiltUrl ( decodedUrl , config ) , undefined ]
396- } else {
397- return [ joinUrlSegments ( config . base , decodedUrl ) , undefined ]
398- }
396+ // } else {
397+ // return [joinUrlSegments(config.base, decodedUrl), undefined]
398+ // }
399399 }
400400 const [ id , fragment ] = decodedUrl . split ( '#' )
401401 let resolved = await resolveUrl ( id , importer )
402402 if ( resolved ) {
403403 if ( fragment ) resolved += '#' + fragment
404404 return [ await fileToUrl ( this , resolved ) , resolved ]
405405 }
406- if ( config . command === 'build' ) {
406+ // if (config.command === 'build') {
407407 const isExternal = config . build . rollupOptions . external
408408 ? resolveUserExternal (
409409 config . build . rollupOptions . external ,
@@ -419,7 +419,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
419419 `\n${ decodedUrl } referenced in ${ id } didn't resolve at build time, it will remain unchanged to be resolved at runtime` ,
420420 )
421421 }
422- }
422+ // }
423423 return [ url , undefined ]
424424 }
425425
@@ -578,46 +578,47 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
578578 ! inlined &&
579579 dataToEsm ( modules , { namedExports : true , preferConst : true } )
580580
581- if ( config . command === 'serve' ) {
582- const getContentWithSourcemap = async ( content : string ) => {
583- if ( config . css . devSourcemap ) {
584- const sourcemap = this . getCombinedSourcemap ( )
585- if ( sourcemap . mappings ) {
586- await injectSourcesContent (
587- sourcemap ,
588- cleanUrl ( id ) ,
589- config . logger ,
590- )
591- }
592- return getCodeWithSourcemap ( 'css' , content , sourcemap )
593- }
594- return content
595- }
596-
597- if ( isDirectCSSRequest ( id ) ) {
598- return null
599- }
600- if ( inlined ) {
601- return `export default ${ JSON . stringify ( css ) } `
602- }
603- if ( this . environment . config . consumer === 'server' ) {
604- return modulesCode || 'export {}'
605- }
606-
607- const cssContent = await getContentWithSourcemap ( css )
608- const code = [
609- `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${ JSON . stringify (
610- path . posix . join ( config . base , CLIENT_PUBLIC_PATH ) ,
611- ) } `,
612- `const __vite__id = ${ JSON . stringify ( id ) } ` ,
613- `const __vite__css = ${ JSON . stringify ( cssContent ) } ` ,
614- `__vite__updateStyle(__vite__id, __vite__css)` ,
615- // css modules exports change on edit so it can't self accept
616- `${ modulesCode || 'import.meta.hot.accept()' } ` ,
617- `import.meta.hot.prune(() => __vite__removeStyle(__vite__id))` ,
618- ] . join ( '\n' )
619- return { code, map : { mappings : '' } }
620- }
581+ // TODO(underfin): css hmr
582+ // if (config.command === 'serve') {
583+ // const getContentWithSourcemap = async (content: string) => {
584+ // if (config.css.devSourcemap) {
585+ // const sourcemap = this.getCombinedSourcemap()
586+ // if (sourcemap.mappings) {
587+ // await injectSourcesContent(
588+ // sourcemap,
589+ // cleanUrl(id),
590+ // config.logger,
591+ // )
592+ // }
593+ // return getCodeWithSourcemap('css', content, sourcemap)
594+ // }
595+ // return content
596+ // }
597+
598+ // if (isDirectCSSRequest(id)) {
599+ // return null
600+ // }
601+ // if (inlined) {
602+ // return `export default ${JSON.stringify(css)}`
603+ // }
604+ // if (this.environment.config.consumer === 'server') {
605+ // return modulesCode || 'export {}'
606+ // }
607+
608+ // const cssContent = await getContentWithSourcemap(css)
609+ // const code = [
610+ // `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify(
611+ // path.posix.join(config.base, CLIENT_PUBLIC_PATH),
612+ // )}`,
613+ // `const __vite__id = ${JSON.stringify(id)}`,
614+ // `const __vite__css = ${JSON.stringify(cssContent)}`,
615+ // `__vite__updateStyle(__vite__id, __vite__css)`,
616+ // // css modules exports change on edit so it can't self accept
617+ // `${modulesCode || 'import.meta.hot.accept()'}`,
618+ // `import.meta.hot.prune(() => __vite__removeStyle(__vite__id))`,
619+ // ].join('\n')
620+ // return { code, map: { mappings: '' } }
621+ // }
621622
622623 // build CSS handling ----------------------------------------------------
623624
@@ -699,7 +700,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
699700 chunkCSS : string ,
700701 cssAssetName : string ,
701702 ) => {
702- const encodedPublicUrls = encodePublicUrlsInCSS ( config )
703+ const encodedPublicUrls = true
703704
704705 const relative = config . base === './' || config . base === ''
705706 const cssAssetDirname =
@@ -3493,9 +3494,10 @@ async function compileLightningCSS(
34933494 } ,
34943495 minify : config . isProduction && ! ! config . build . cssMinify ,
34953496 sourceMap :
3496- config . command === 'build'
3497- ? ! ! config . build . sourcemap
3498- : config . css . devSourcemap ,
3497+ // config.command === 'build' ?
3498+ ! ! config . build . sourcemap ,
3499+ // TODO(underfin): deprecate css.devSourcemap
3500+ // : config.css.devSourcemap,
34993501 analyzeDependencies : true ,
35003502 cssModules : cssModuleRE . test ( id )
35013503 ? ( config . css . lightningcss ?. cssModules ?? true )
0 commit comments