Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sass importer can't be undefined (fix: #3390) #3395

Merged
merged 1 commit into from May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 32 additions & 9 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -859,15 +859,26 @@ type PreprocessorAdditionalData =
| string
| ((source: string, filename: string) => string | Promise<string>)

type StylePreprocessorOptions = {
[key: string]: any
additionalData?: PreprocessorAdditionalData
filename: string
alias: Alias[]
}

type SassStylePreprocessorOptions = StylePreprocessorOptions & Sass.Options

type StylePreprocessor = (
source: string,
root: string,
options: {
[key: string]: any
additionalData?: PreprocessorAdditionalData
filename: string
alias: Alias[]
},
options: StylePreprocessorOptions,
resolvers: CSSAtImportResolvers
) => StylePreprocessorResults | Promise<StylePreprocessorResults>

type SassStylePreprocessor = (
source: string,
root: string,
options: SassStylePreprocessorOptions,
resolvers: CSSAtImportResolvers
) => StylePreprocessorResults | Promise<StylePreprocessorResults>

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

// .scss/.sass processor
const scss: StylePreprocessor = async (source, root, options, resolvers) => {
const scss: SassStylePreprocessor = async (
source,
root,
options,
resolvers
) => {
const render = loadPreprocessor(PreprocessLang.sass, root).render
const internalImporter: Sass.Importer = (url, importer, done) => {
resolvers.sass(url, importer).then((resolved) => {
Expand All @@ -913,12 +929,19 @@ const scss: StylePreprocessor = async (source, root, options, resolvers) => {
}
})
}
const importer = [internalImporter]
if (options.importer) {
Array.isArray(options.importer)
? importer.concat(options.importer)
: importer.push(options.importer)
}

const finalOptions: Sass.Options = {
...options,
data: await getSource(source, options.filename, options.additionalData),
file: options.filename,
outFile: options.filename,
importer: [internalImporter].concat(options.importer)
importer
}

try {
Expand Down Expand Up @@ -946,7 +969,7 @@ const scss: StylePreprocessor = async (source, root, options, resolvers) => {
}
}

const sass: StylePreprocessor = (source, root, options, aliasResolver) =>
const sass: SassStylePreprocessor = (source, root, options, aliasResolver) =>
scss(
source,
root,
Expand Down