11import path from 'upath'
2+ import fs from 'node:fs/promises'
23import { resolveVuetifyBase , normalizePath , isObject } from '@vuetify/loader-shared'
34
45import type { Plugin } from 'vite'
@@ -18,6 +19,23 @@ export function stylesPlugin (options: Options): Plugin {
1819
1920 let configFile : string
2021 const tempFiles = new Map < string , string > ( )
22+ const mappings = new Map < string , string > ( )
23+
24+ async function resolveCss ( target : string ) {
25+ let mapping = mappings . get ( target )
26+ if ( ! mapping ) {
27+ try {
28+ mapping = target . replace ( / \. c s s $ / , '.sass' )
29+ await fs . access ( mapping , fs . constants . R_OK )
30+ } catch ( err ) {
31+ if ( ! ( err instanceof Error && 'code' in err && err . code === 'ENOENT' ) ) throw err
32+ mapping = target . replace ( / \. c s s $ / , '.scss' )
33+ }
34+ mappings . set ( target , mapping )
35+ }
36+
37+ return mapping
38+ }
2139
2240 return {
2341 name : 'vuetify:styles' ,
@@ -42,16 +60,17 @@ export function stylesPlugin (options: Options): Plugin {
4260 if ( options . styles === 'none' ) {
4361 return `${ PLUGIN_VIRTUAL_PREFIX } __void__`
4462 } else if ( options . styles === 'sass' ) {
45- const target = source . replace ( / \. c s s $ / , '.sass' )
63+ const target = await resolveCss ( source )
4664 return this . resolve ( target , importer , { skipSelf : true , custom } )
4765 } else if ( isObject ( options . styles ) ) {
4866 const resolution = await this . resolve ( source , importer , { skipSelf : true , custom } )
4967
5068 if ( ! resolution ) return null
5169
52- const target = resolution . id . replace ( / \. c s s $ / , '.sass' )
70+ const target = await resolveCss ( resolution . id )
5371 const file = path . relative ( path . join ( vuetifyBase , 'lib' ) , target )
54- const contents = `@use "${ normalizePath ( configFile ) } "\n@use "${ normalizePath ( target ) } "`
72+ const suffix = target . match ( / \. s c s s / ) ? ';\n' : '\n'
73+ const contents = `@use "${ normalizePath ( configFile ) } "${ suffix } @use "${ normalizePath ( target ) } "${ suffix } `
5574
5675 tempFiles . set ( file , contents )
5776
0 commit comments