Skip to content

Commit 30ff5a2

Browse files
authored
fix: sass importer can't be undefined (fix: #3390) (#3395)
1 parent b0b62f9 commit 30ff5a2

File tree

1 file changed

+32
-9
lines changed
  • packages/vite/src/node/plugins

1 file changed

+32
-9
lines changed

packages/vite/src/node/plugins/css.ts

+32-9
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,26 @@ type PreprocessorAdditionalData =
859859
| string
860860
| ((source: string, filename: string) => string | Promise<string>)
861861

862+
type StylePreprocessorOptions = {
863+
[key: string]: any
864+
additionalData?: PreprocessorAdditionalData
865+
filename: string
866+
alias: Alias[]
867+
}
868+
869+
type SassStylePreprocessorOptions = StylePreprocessorOptions & Sass.Options
870+
862871
type StylePreprocessor = (
863872
source: string,
864873
root: string,
865-
options: {
866-
[key: string]: any
867-
additionalData?: PreprocessorAdditionalData
868-
filename: string
869-
alias: Alias[]
870-
},
874+
options: StylePreprocessorOptions,
875+
resolvers: CSSAtImportResolvers
876+
) => StylePreprocessorResults | Promise<StylePreprocessorResults>
877+
878+
type SassStylePreprocessor = (
879+
source: string,
880+
root: string,
881+
options: SassStylePreprocessorOptions,
871882
resolvers: CSSAtImportResolvers
872883
) => StylePreprocessorResults | Promise<StylePreprocessorResults>
873884

@@ -902,7 +913,12 @@ function loadPreprocessor(lang: PreprocessLang, root: string): any {
902913
}
903914

904915
// .scss/.sass processor
905-
const scss: StylePreprocessor = async (source, root, options, resolvers) => {
916+
const scss: SassStylePreprocessor = async (
917+
source,
918+
root,
919+
options,
920+
resolvers
921+
) => {
906922
const render = loadPreprocessor(PreprocessLang.sass, root).render
907923
const internalImporter: Sass.Importer = (url, importer, done) => {
908924
resolvers.sass(url, importer).then((resolved) => {
@@ -913,12 +929,19 @@ const scss: StylePreprocessor = async (source, root, options, resolvers) => {
913929
}
914930
})
915931
}
932+
const importer = [internalImporter]
933+
if (options.importer) {
934+
Array.isArray(options.importer)
935+
? importer.concat(options.importer)
936+
: importer.push(options.importer)
937+
}
938+
916939
const finalOptions: Sass.Options = {
917940
...options,
918941
data: await getSource(source, options.filename, options.additionalData),
919942
file: options.filename,
920943
outFile: options.filename,
921-
importer: [internalImporter].concat(options.importer)
944+
importer
922945
}
923946

924947
try {
@@ -946,7 +969,7 @@ const scss: StylePreprocessor = async (source, root, options, resolvers) => {
946969
}
947970
}
948971

949-
const sass: StylePreprocessor = (source, root, options, aliasResolver) =>
972+
const sass: SassStylePreprocessor = (source, root, options, aliasResolver) =>
950973
scss(
951974
source,
952975
root,

0 commit comments

Comments
 (0)