MCPcopy
hub / github.com/vuejs/core / scss

Function scss

packages/compiler-sfc/src/style/preprocessors.ts:25–71  ·  view source on GitHub ↗
(source, map, options, load = require)

Source from the content-addressed store, hash-verified

23
24// .scss/.sass processor
25const scss: StylePreprocessor = (source, map, options, load = require) => {
26 const nodeSass: typeof import('sass') = load('sass')
27 const { compileString, renderSync } = nodeSass
28
29 const data = getSource(source, options.filename, options.additionalData)
30 let css: string
31 let dependencies: string[]
32 let sourceMap: any
33
34 try {
35 if (compileString) {
36 const { pathToFileURL, fileURLToPath }: typeof import('url') = load('url')
37
38 const result = compileString(data, {
39 ...options,
40 url: pathToFileURL(options.filename),
41 sourceMap: !!map,
42 })
43 css = result.css
44 dependencies = result.loadedUrls.map(url => fileURLToPath(url))
45 sourceMap = map ? result.sourceMap! : undefined
46 } else {
47 const result = renderSync({
48 ...options,
49 data,
50 file: options.filename,
51 outFile: options.filename,
52 sourceMap: !!map,
53 })
54 css = result.css.toString()
55 dependencies = result.stats.includedFiles
56 sourceMap = map ? JSON.parse(result.map!.toString()) : undefined
57 }
58
59 if (map) {
60 return {
61 code: css,
62 errors: [],
63 dependencies,
64 map: merge(map, sourceMap!),
65 }
66 }
67 return { code: css, errors: [], dependencies }
68 } catch (e: any) {
69 return { code: '', errors: [e], dependencies: [] }
70 }
71}
72
73const sass: StylePreprocessor = (source, map, options, load) =>
74 scss(

Callers 1

sassFunction · 0.85

Calls 5

getSourceFunction · 0.85
mapMethod · 0.80
toStringMethod · 0.80
parseMethod · 0.65
loadFunction · 0.50

Tested by

no test coverage detected