Skip to content

Commit

Permalink
Switch from node-sass to sass
Browse files Browse the repository at this point in the history
node-sass is deprecated and doesn't work on newer platforms (e.g. arm64)
  • Loading branch information
Jacopo Beschi committed Dec 17, 2024
1 parent 32b0431 commit 903b51f
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 1,067 deletions.
18 changes: 0 additions & 18 deletions assets/trix/stylesheets/functions.js

This file was deleted.

41 changes: 41 additions & 0 deletions bin/sass-build
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")
}
}
)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@
"karma-chrome-launcher": "3.2.0",
"karma-qunit": "^4.1.2",
"karma-sauce-launcher": "^4.3.6",
"node-sass": "^7.0.1",
"qunit": "2.19.1",
"rangy": "^1.3.0",
"rollup": "^2.56.3",
"rollup-plugin-includepaths": "^0.2.4",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.83.0",
"svgo": "^2.8.0",
"webdriverio": "^7.19.5"
},
"resolutions": {
"webdriverio": "^7.19.5"
},
"scripts": {
"build-css": "node-sass --functions=./assets/trix/stylesheets/functions assets/trix.scss dist/trix.css",
"build-css": "bin/sass-build assets/trix.scss dist/trix.css",
"build-js": "rollup -c",
"build-assets": "cp -f assets/*.html dist/",
"build": "yarn run build-js && yarn run build-css && yarn run build-assets",
Expand Down
Loading

0 comments on commit 903b51f

Please sign in to comment.