Monitoring changes in SASS files using node-sass through NPM

I have node-sass installed with the options set according to the guidance provided in a response on Using node-sass watch option with npm run-script, however, I am facing issues with it not working as expected.

Below is the content of my package.json file which outlines my latest attempt:

{
  "name": "linkup-paints",
  "description": "NPM for Linkup Paint Supplies website for 2019",
  "version": "1.0.2",
  "main": "index.js",
  "scripts": {
    "start": "run-script-os",
    "start:win32": "browser-sync start --server --files '**/*.css, **/*.html, **/*.js, !node_modules/**/*, !styles/**/*' --directory --port 7777 --browser \"C:\\Program Files\\Firefox Developer Edition\\firefox.exe\"",
    "build-sass": "node-sass styles/main.scss css/main.css",
    "watch-sass": "node-sass -w styles/main.scss css/main.css"
  },
  "author": "dpDesignz",
  "license": "ISC",
  "devDependencies": {
    "browser-sync": "^2.26.3",
    "run-script-os": "^1.0.3",
    "node-sass": "^4.9.4"
  }
}

I have attempted the following solutions:

"build:sass": "node-sass -r --output-style compressed styles/main.scss -o css/main.css",
"watch:sass": "npm run build:sass && npm run build:sass -- -w"

I also tried:

"css": "node-sass styles/main.scss -o css/main.css",
"css:watch": "npm run css && node-sass styles/main.scss -wo css/main.css"

Furthermore, I attempted:

"scss": "node-sass --watch styles/main.scss -o css/main.css"

and (as suggested by sidthesloth):

"build-sass": "node-sass styles/main.scss css/main.css",
"watch-sass": "node-sass -w styles/main.scss css/main.css"

After running npm i, followed by npm start, browser-sync initiates and observes file changes. However, my css/main.css does not compile or update when I modify an .scss file.

I am relatively new to using NPM, so any assistance would be greatly appreciated. Despite going through various tutorials and answers, including Using node-sass, Watch and Compile Sass in Five Quick Steps, and Using node-sass to compile Sass files in an npm script) for the past couple of hours, I have been unable to resolve the issue.

What steps can I take to ensure that my watch and build commands function correctly?

Update

For anyone encountering a similar issue in the future, I realized that my scripts were not executing parallelly because I did not fully comprehend how scripts operate. I mistakenly assumed that running npm start would trigger all scripts simultaneously when, in fact, they needed to be individually called. Here's the revised version of my package.json file:

{
  "name": "linkup-paints",
  "version": "1.0.3",
  "description": "NPM for Linkup Paint Supplies website for 2019",
  "main": "index.js",
  "directories": {
    "lib": "lib"
  },
  "scripts": {
    "start": "npm-run-all --parallel browser-sync build-sass watch-sass",
    "browser-sync": "browser-sync start --server --files '**/*.css, **/*.html, **/*.js, !node_modules/**/*' -w --directory --port 7777 --browser \"C:\\Program Files\\Firefox Developer Edition\\firefox.exe\"",
    "build-sass": "node-sass styles/main.scss css/main.css",
    "watch-sass": "node-sass -w styles/main.scss css/main.css"
  },
  "keywords": [
    "linkup",
    "2019"
  ],
  "repository": {},
  "author": "dpDesignz",
  "license": "ISC",
  "devDependencies": {
    "npm-run-all": "^4.1.3",
    "browser-sync": "^2.26.3",
    "node-sass": "^4.9.4"
  },
  "bugs": {
    "url": "http://support.dpdesignz.co"
  },
  "homepage": "http://www.dpdesignz.co"
}

To address this issue, I introduced the npm-run-all script and modified the arguments in the start section to

npm-run-all --parallel browser-sync build-sass watch-sass
. As I no longer required cross-operating system compatibility from the old run-script-os arguments, I made these adjustments. Additionally, I included the -w (--watch) argument in the browser-sync line to prompt synchronization due to the replacement nature of the created .css files during the build process, rather than merely modifying them as mandated by browser-sync by default.

Answer №1

In my workflow, I rely on two NPM scripts for compiling or monitoring SCSS files using node-sass:

"compile-scss": "node-sass src/styles/main.scss dist/styles/main.css"
"watch-scss": "node-sass -w src/styles/main.scss dist/styles/main.css"

I hope you find these helpful in your projects.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript Animation of Text

I have a challenge where I want to animate text's opacity in JavaScript after the user presses enter. However, I am struggling to achieve this with my current code. I can provide all of my code for you to review and help me understand why the animatio ...

I'm struggling to center my navigation bar and adjust its size properly, causing the page to overflow

I am facing some issues with my navigation bar. I am unable to adjust its size or position it at the center of the page. Additionally, despite setting the body width and height to 100vw and 100vh respectively, I am able to scroll both vertically and horizo ...

What is the method used to incorporate the radial gradient in this design?

As I was browsing the internet, I came across several websites with beautiful natural gradients on their backgrounds. However, I'm puzzled as to how they achieved this effect. It doesn't seem like a simple image file because the gradient adjusts ...

Replace the data within the internal document using NodeJS

I'm relatively new to NodeJS and programming in general, starting around the age of 9 or 10 (I'm currently 13). Before diving deeper into NodeJS, I want to ensure that I'm using it correctly. Having worked with PHP for some time, I've ...

What could be causing the 'public' directory to not be served by app.use() after saving, even though the path seems to be correct?

I'm currently working on a tutorial for node and express, but I am facing an issue with the app.use function. Despite following the tutorial exactly, the public directory is not being served as expected. When I visit localhost:3000, I see the word Wea ...

Retrieving Browser URL using Node.js

Currently, I am trying to extract the browser URL from a user who has integrated my external JavaScript file into their website. The process involves them including the JS file, which triggers an Ajax call using jQuery to communicate with my Node server. ...

The HTTP server is operating in the background

After successfully installing npm http-server, I am pleased with how well it shares my directory with other local PCs. However, I am now faced with the challenge of running it in the background. Despite attempts to do so using commands like http-server . ...

Ways to prevent a floated element from impacting text-align: center styling?

Within my code, there is a <p> element structured as follows: <div><p>Text Goes Here <span></span</p></div> The CSS I currently have is: div { text-align:center } span { float:right } An issue arises when I populate ...

JSFiddle showcasing the Bootstrap grid system

I'm having trouble implementing bootstrap's grid system on jsfiddle. Check it out on jsfiddle I've tried using the example from the bootstrap documentation: <div class="row"> <div class="col-md-1">.col-md-1</div> ...

Is there a way to achieve element scrolling similar to scrollLeft within a scrollable container without using JavaScript

Looking for a CSS Solution: Is there a way to achieve element.scrollLeft functionality in CSS without using javascript? I want to pre-scroll a scrollable container. Situation Overview: I have a scrollable container that houses various items. Some instanc ...

The structure of NodeJS Express API calls revolves around handling asynchronous events

Currently, I am working on a hobby project using NodeJS and Express, but I am finding it challenging to manage asynchronous calls. There is a bug that I would like the community's help in resolving. I have set up an Express layout where I send post r ...

Creating a grid layout with images encapsulated within a div using HTML

I am struggling to create a grid of images with padding between them inside the main_block div. The issue I'm facing is that I can't get the images to align next to each other using inline block or break them with a because they go in line ins ...

Utilize Docker GitHub actions to efficiently store npm packages in a cache

I've set up GitHub actions to test a nodeJS project within a Docker container (node:16-alpine). However, I'm facing an issue where yarn install re-installs all the packages every time. How can I cache these packages to save time between runs? I& ...

Variation in element widths and CSS widths

While inspecting an element in FF, it displays a width of 225px. However, the applied CSS sets the width to 207px for this element. The discrepancy may be due to Bootstrap and varying resolutions. Is there a tool available to identify chang ...

Is it possible to dynamically assign trigger and target divs to bPopup?

On our ColdFusion page, we have a dynamic list of paired divs created using a loop over a query. For example, each pair consists of internshipHandleX and internshipHiddenX: <div id="internshipHidden#internship.currentrow#" class="hidden pop-up"> We ...

I recently started using mongoDB atlas and have encountered a MongoServerError. Surprisingly, when I run the program without an .env file, everything runs smoothly. However, as soon as I include

PORT= <port> DB_HOST= <host> DB_URI= <uri> DB_NAME= <db> DB_USER= <user> DB_PASS= <pass> // app.js file import express from 'express'; import mongoose from 'mongoose&apo ...

Tips for resolving the error message "An issue occurred with the skill's response" within the Alexa Developer Console

Looking to develop a basic Alexa app where users can interact with voice commands, but encountering an issue with the response in the Test tab of Alexa Developer Console. The error message states "There was a problem with the requested skill's respons ...

Leveraging this jQuery code across multiple div elements

As a newcomer to jQuery, I am currently experimenting with a test script. My goal is to create an effect where when an image is clicked, a div slides down displaying more information similar to the new google images effect. The issue with the current scri ...

Importing a JavaScript file into another JavaScript file

var FS = require('fs'); var Path = require('path'); var Jsonfile = require('jsonfile'); var search = function () {}; search.prototype.projectContainerDirPath = null; /* * interface */ search.prototype.setPaths = function ...

CSS guidelines for layering shapes and divs

Currently, I am in the process of developing a screenshot application to enhance my understanding of HTML, CSS, and Electron. One of the key features I have implemented is a toggleable overlay consisting of a 0.25 opacity transparent box that covers the en ...