-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Switch to node-sass to sass
node-sass is deprecated and doesn't work on newer platforms (e.g. arm64)
Jacopo Beschi
committed
Dec 17, 2024
1 parent
32b0431
commit 7d48cb4
Showing
4 changed files
with
222 additions
and
1,067 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require("path") | ||
const fs = require("fs") | ||
const sass = require("sass") | ||
const { optimize } = require("svgo") | ||
|
||
const args = process.argv.slice(2) | ||
if (args.length < 2) { | ||
console.error("Usage: bin/sass-build <inputFile> <outputFile>") | ||
process.exit(1) | ||
} | ||
const inputFile = path.resolve(args[0]) | ||
const outputFile = path.resolve(args[1]) | ||
|
||
const basePath = path.dirname(inputFile) | ||
|
||
const functions = { | ||
"svg($file)": (svgFileName) => { | ||
const filename = path.resolve(basePath, svgFileName.getValue()) | ||
|
||
let svgContent = fs.readFileSync(filename, "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") | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.