Skip to content

Commit 903b51f

Browse files
author
Jacopo Beschi
committed
Switch from node-sass to sass
node-sass is deprecated and doesn't work on newer platforms (e.g. arm64)
1 parent 32b0431 commit 903b51f

File tree

4 files changed

+222
-1067
lines changed

4 files changed

+222
-1067
lines changed

assets/trix/stylesheets/functions.js

-18
This file was deleted.

bin/sass-build

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
3+
const path = require("path")
4+
const fs = require("fs")
5+
const sass = require("sass")
6+
const { optimize } = require("svgo")
7+
8+
const args = process.argv.slice(2)
9+
if (args.length < 2) {
10+
console.error("Usage: bin/sass-build <inputFile> <outputFile>")
11+
process.exit(1)
12+
}
13+
const inputFile = path.resolve(args[0])
14+
const outputFile = path.resolve(args[1])
15+
16+
const basePath = path.dirname(inputFile)
17+
18+
const functions = {
19+
"svg($file)": (svgFileName) => {
20+
const filename = path.resolve(basePath, svgFileName.getValue())
21+
22+
let svgContent = fs.readFileSync(filename, "utf8")
23+
svgContent = optimize(svgContent, { multipass: true, datauri: "enc" })
24+
25+
return new sass.SassString(`url("${svgContent.data}")`, { quotes: false })
26+
},
27+
}
28+
29+
sass.render(
30+
{
31+
file: inputFile,
32+
functions
33+
},
34+
(err, result) => {
35+
if (err) {
36+
console.error("Error compiling SCSS:", err)
37+
} else {
38+
fs.writeFileSync(outputFile, result.css, "utf8")
39+
}
40+
}
41+
)

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@
4242
"karma-chrome-launcher": "3.2.0",
4343
"karma-qunit": "^4.1.2",
4444
"karma-sauce-launcher": "^4.3.6",
45-
"node-sass": "^7.0.1",
4645
"qunit": "2.19.1",
4746
"rangy": "^1.3.0",
4847
"rollup": "^2.56.3",
4948
"rollup-plugin-includepaths": "^0.2.4",
5049
"rollup-plugin-terser": "^7.0.2",
50+
"sass": "^1.83.0",
5151
"svgo": "^2.8.0",
5252
"webdriverio": "^7.19.5"
5353
},
5454
"resolutions": {
5555
"webdriverio": "^7.19.5"
5656
},
5757
"scripts": {
58-
"build-css": "node-sass --functions=./assets/trix/stylesheets/functions assets/trix.scss dist/trix.css",
58+
"build-css": "bin/sass-build assets/trix.scss dist/trix.css",
5959
"build-js": "rollup -c",
6060
"build-assets": "cp -f assets/*.html dist/",
6161
"build": "yarn run build-js && yarn run build-css && yarn run build-assets",

0 commit comments

Comments
 (0)