Skip to content

Commit

Permalink
refactor: support modern api
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Sep 22, 2024
1 parent aad407d commit 637b137
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/compiler-sfc/src/style/preprocessors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import merge from 'merge-source-map'
import { fileURLToPath, pathToFileURL } from 'url'
import type { RawSourceMap } from '@vue/compiler-core'
import type { SFCStyleCompileOptions } from '../compileStyle'
import { isFunction } from '@vue/shared'
Expand All @@ -23,23 +24,21 @@ export interface StylePreprocessorResults {

// .scss/.sass processor
const scss: StylePreprocessor = (source, map, options, load = require) => {
const nodeSass = load('sass')
const finalOptions = {
const nodeSass = load('sass') as typeof import('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,
silenceDeprecations: ['legacy-js-api'],
}

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())),
map: merge(map, JSON.parse(result.sourceMap?.toString() ?? '')),
errors: [],
dependencies,
}
Expand Down

0 comments on commit 637b137

Please sign in to comment.