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

refactor(compiler-sfc): support sass modern api #11992

Merged
merged 9 commits into from
Oct 11, 2024
20 changes: 10 additions & 10 deletions packages/compiler-sfc/src/style/preprocessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ export interface StylePreprocessorResults {

// .scss/.sass processor
const scss: StylePreprocessor = (source, map, options, load = require) => {
const nodeSass = load('sass')
const finalOptions = {
const { pathToFileURL, fileURLToPath }: typeof import('url') = load('url')
const nodeSass: typeof import('sass') = load('sass')
const data = getSource(source, options.filename, options.additionalData)
const finalOptions: import('sass').StringOptions<'sync'> = {
...options,
data: getSource(source, options.filename, options.additionalData),
file: options.filename,
outFile: options.filename,
url: pathToFileURL(options.filename),
sourceMap: !!map,
}

try {
const result = nodeSass.renderSync(finalOptions)
const dependencies = result.stats.includedFiles
const result = nodeSass.compileString(data, finalOptions)
const dependencies = result.loadedUrls.map(url => fileURLToPath(url))
if (map) {
return {
code: result.css.toString(),
map: merge(map, JSON.parse(result.map.toString())),
code: result.css,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The css type has changed from Buffer to string, and toString is no longer required.
sourceMap as well

map: merge(map, result.sourceMap!),
errors: [],
dependencies,
}
}

return { code: result.css.toString(), errors: [], dependencies }
return { code: result.css, errors: [], dependencies }
} catch (e: any) {
return { code: '', errors: [e], dependencies: [] }
}
Expand Down