Skip to content

Commit bcc0703

Browse files
authored
Merge pull request #118 from activeguild/bugfix/117
Bugfix/117
2 parents f53c873 + 5bc5f77 commit bcc0703

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-sass-dts",
3-
"version": "1.3.30",
3+
"version": "1.3.31",
44
"engines": {
55
"node": ">=20"
66
},
@@ -73,7 +73,7 @@
7373
"peerDependencies": {
7474
"postcss": "^8",
7575
"prettier": "^2.7 || ^3",
76-
"vite": ">=3",
76+
"vite": "^7",
7777
"sass-embedded": "^1.78.0"
7878
},
7979
"lint-staged": {

src/css.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ export const parseCss = async (
4848
}
4949

5050
const data = await getData(file.toString(), fileName, options.additionalData)
51-
const finalImporter: Sass.LegacyAsyncImporter[] = []
51+
if (options.api === 'legacy') {
52+
// Legacy API
53+
const finalImporter: Sass.LegacyAsyncImporter[] = []
5254

53-
if (options.api !== 'modern' && options.api !== 'modern-compiler') {
5455
if (options.importer) {
5556
Array.isArray(options.importer)
5657
? finalImporter.push(...options.importer)
@@ -64,7 +65,6 @@ export const parseCss = async (
6465
{
6566
...options,
6667
data,
67-
pkgImporter: new sass.NodePackageImporter(),
6868
file: fileName,
6969
includePaths: ['node_modules'],
7070
importer: finalImporter,
@@ -83,16 +83,21 @@ export const parseCss = async (
8383
const splitted = result.css.toString().split(SPLIT_STR)
8484
return { localStyle: splitted[1] || '', globalStyle: splitted[0] }
8585
} else {
86+
// Modern API (modern / modern-compiler)
87+
const finalImporters: Sass.Importer<'async'>[] = []
88+
8689
if (options.importers) {
8790
Array.isArray(options.importers)
88-
? finalImporter.push(...options.importers)
89-
: finalImporter.push(options.importers)
91+
? finalImporters.push(...options.importers)
92+
: finalImporters.push(options.importers)
9093
}
9194

92-
const sassOptions = { ...options }
93-
sassOptions.url = pathToFileURL(fileName)
94-
sassOptions.pkgImporter = new sass.NodePackageImporter()
95-
sassOptions.importers = finalImporter
95+
const sassOptions: Sass.StringOptions<'async'> = {
96+
...options,
97+
url: pathToFileURL(fileName),
98+
importers: finalImporters,
99+
syntax: fileName.endsWith('.sass') ? 'indented' : 'scss',
100+
}
96101

97102
const result = await sass.compileStringAsync(data, sassOptions)
98103
const splitted = result.css.toString().split(SPLIT_STR)

0 commit comments

Comments
 (0)