Skip to content

Commit ae3e036

Browse files
disfatedrstoenescu
andauthored
fix(vite-plugin): sass variables for files with only @use statements (#13371)
* sass variables for files with only @use statements scss-transform will fail currently for file like this: ```sass @use 'A' @use 'B' -- no new line here ``` gives ``` [vite] Internal server error: @use rules must be written before any other rules. ``` * Update scss-transform.js Co-authored-by: Razvan Stoenescu <razvan.stoenescu@gmail.com>
1 parent 4fde304 commit ae3e036

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

vite-plugin/src/scss-transform.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ export function createScssTransform (fileExtension, sassVariables) {
2323
return prefix + content
2424
}
2525

26-
const newLineIndex = content.indexOf('\n', useIndex) + 1
27-
return content.substring(0, newLineIndex) + prefix + content.substring(newLineIndex)
26+
const newLineIndex = content.indexOf('\n', useIndex)
27+
28+
if (newLineIndex !== -1) {
29+
const index = newLineIndex + 1
30+
return content.substring(0, index) + prefix + content.substring(index)
31+
}
32+
33+
return content + '\n' + prefix
2834
}
2935
}

0 commit comments

Comments
 (0)