Skip to content

Commit

Permalink
SCSS: Switch to compile
Browse files Browse the repository at this point in the history
Use `compile` instead the deprecated `render` method.
No changes to the generated `.css`.

See https://sass-lang.com/documentation/js-api/functions/render/
  • Loading branch information
Jacopo Beschi committed Dec 17, 2024
1 parent 6214af4 commit b67b642
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions bin/sass-build
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@ const outputFile = path.resolve(args[1])
const basePath = path.dirname(inputFile)

const functions = {
"svg($file)": (svgFileName) => {
const filename = path.resolve(basePath, svgFileName.getValue())
"svg($file)": (args) => {
const fileName = args[0].assertString().text
const filePath = path.resolve(basePath, fileName)

let svgContent = fs.readFileSync(filename, "utf8")
svgContent = optimize(svgContent, { multipass: true, datauri: "enc" })
let svgContent = fs.readFileSync(filePath, "utf8");
svgContent = optimize(svgContent, { multipass: true, datauri: "enc" });

return new sass.SassString(`url("${svgContent.data}")`, { quotes: false })
},
}
}

sass.render(
{
file: inputFile,
functions
},
(err, result) => {
if (err) {
console.error("Error compiling SCSS:", err)
} else {
fs.writeFileSync(outputFile, result.css, "utf8")
}
}
)
try {
const result = sass.compile(inputFile, {
functions,
})

fs.writeFileSync(outputFile, result.css, "utf8")
} catch (error) {
console.error("Error compiling SCSS:", error.message)
process.exit(1)
}

0 comments on commit b67b642

Please sign in to comment.