Repository: vitejs/vite
File: packages/vite/src/node/plugins/css.ts (TypeScript)

Code before:
          const referenceId = this.emitFile({
            type: 'asset',
            name: cssAssetName,
            originalFileName,
            source: content,
          })

          const filename = this.getFileName(referenceId)
          chunk.viteMetadata!.importedAssets.add(cleanUrl(filename))
          const replacement = toOutputFilePathInJS(
            this.environment,
            filename,
            'asset',
            chunk.fileName,
            'js',
            toRelativeRuntime,
          )
          const replacementString =
            typeof replacement === 'string'
              ? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
              : `"+${replacement.runtime}+"`
          s.update(start, end, replacementString)
        }
      }

      if (chunkCSS || (isPureCssChunk && chunk.isEntry)) {
        if (isPureCssChunk && (opts.format === 'es' || opts.format === 'cjs')) {
          // this is a shared CSS-only chunk that is empty.
          pureCssChunks.add(chunk)
        }

        if (this.environment.config.build.cssCodeSplit) {
          if (opts.format === 'es' || opts.format === 'cjs') {
            const isEntry = chunk.isEntry && isPureCssChunk
            const cssFullAssetName = ensureFileExt(chunk.name, '.css')
            // if facadeModuleId doesn't exist or doesn't have a CSS extension,
            // that means a JS entry file imports a CSS file.
            // in this case, only use the filename for the CSS chunk name like JS chunks.
            const cssAssetName =
              chunk.isEntry &&
              (!chunk.facadeModuleId || !isCSSRequest(chunk.facadeModuleId))
                ? path.basename(cssFullAssetName)
                : cssFullAssetName
            const originalFileName = getChunkOriginalFileName(
              chunk,
              config.root,
              opts.format,
            )

            chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssAssetName)


Review comment (suggestion):
instead of changing this condition. make the default value of `chunkCSS` be `undefined` and check whether it's `undefined` here.

Code after:
          const referenceId = this.emitFile({
            type: 'asset',
            name: cssAssetName,
            originalFileName,
            source: content,
          })

          const filename = this.getFileName(referenceId)
          chunk.viteMetadata!.importedAssets.add(cleanUrl(filename))
          const replacement = toOutputFilePathInJS(
            this.environment,
            filename,
            'asset',
            chunk.fileName,
            'js',
            toRelativeRuntime,
          )
          const replacementString =
            typeof replacement === 'string'
              ? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
              : `"+${replacement.runtime}+"`
          s.update(start, end, replacementString)
        }
      }

      if (chunkCSS !== undefined) {
        if (isPureCssChunk && (opts.format === 'es' || opts.format === 'cjs')) {
          // this is a shared CSS-only chunk that is empty.
          pureCssChunks.add(chunk)
        }

        if (this.environment.config.build.cssCodeSplit) {
          if (opts.format === 'es' || opts.format === 'cjs') {
            const isEntry = chunk.isEntry && isPureCssChunk
            const cssFullAssetName = ensureFileExt(chunk.name, '.css')
            // if facadeModuleId doesn't exist or doesn't have a CSS extension,
            // that means a JS entry file imports a CSS file.
            // in this case, only use the filename for the CSS chunk name like JS chunks.
            const cssAssetName =
              chunk.isEntry &&
              (!chunk.facadeModuleId || !isCSSRequest(chunk.facadeModuleId))
                ? path.basename(cssFullAssetName)
                : cssFullAssetName
            const originalFileName = getChunkOriginalFileName(
              chunk,
              config.root,
              opts.format,
            )

            chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssAssetName)