I have a Drupal project where I would like to use Node.js build scripts to compile SCSS into CSS.
First, download and install Microsoft's VS Code editor if you haven't already. Then launch the editor so you can download the Live Sass Compiler extension. And that's all you have to do. Once the installation is done, you'll be able to use Sass in your projects.
The term SCSS is an acronym for Sassy Cascading Style Sheets. It is basically a more advanced and evolved variant of the CSS language. Natalie Weizenbaum and Chris Eppstein created it, and Hampton Catlin designed it. It comes with more advanced features- thus often called Sassy CSS.
I use a separate sidecar container that constantly watches for changes to SCSS in my Drupal theme and builds the CSS.
I have a .ddev/docker-compose.sass-watch.yaml
file with the following:
version: "3.6"
services:
sass-watch:
container_name: ddev-${DDEV_SITENAME}-sass-watch
image: node:12
user: $DDEV_UID:$DDEV_GID
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
volumes:
- type: bind
source: ../drupal/web/themes/custom/MY_THEME
target: /app
consistency: cached
- ".:/mnt/ddev_config:ro"
working_dir: /app
command: ["sh", "-c", "npm i && npm run watch"]
Then inside my theme directory I have a package.json
as follows:
{
"name": "MY_THEME",
"scripts": {
"build": "node-sass scss -o css --output-style compressed",
"watch": "node-sass scss -o css --output-style compressed --source-map true -w"
},
"dependencies": {
"node-sass": "^4.14.1"
}
}
The watch
command runs permanently in the background while my ddev project is running.
I can also use ddev logs -s sass-watch
to get the output from the watch command if the build doesn't look like it has worked for some reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With