Skip to content

Commit

Permalink
Merge pull request #1215 from basecamp/switch-to-sass
Browse files Browse the repository at this point in the history
Switch from node-sass to sass
  • Loading branch information
jorgemanrubia authored Dec 17, 2024
2 parents f4d8e5c + 903b51f commit 6214af4
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 6214af4

Please sign in to comment.