Guide on compiling SCSS to CSS when running npm start

When running my application with npm start, I'm unable to compile scss files to css live. Is there a way to achieve live reload for sass to css similar to how ts are compiled to js by the tsc:w utility? Currently, I have to stop the build, then run gulp watch or node-sass command to compile scss to css, and finally restart the solution using npm start. I've tried different approaches but none seem to work. Below is the code snippet from package.json:

Using gulp watch:

"start": "concurrently \"npm run tsc:w\" \"npm run lite\" \"gulp\" ", 
//also tried gulp watch and that did not work too.
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" \"gulp watch\" ",

Gulpfile.js in the root directory looks like this:

'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
  gulp.src('./sass/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./css'));
});
gulp.task('watch', function () {
  gulp.watch('./sass/**/*.scss', ['sass']);
});

Using node-sass command:

"start": "concurrently \"npm run tsc:w\" \"npm run lite\" \"npm run sass\" ",             
"sass": "node-sass -w app/sass/ -o app/css/",

If anyone could shed some light on what I might be missing or provide guidance on the correct approach, it would be greatly appreciated. Thanks in advance!

Answer №1

If you're facing the same issue, you can find a solution in other related discussions as well, such as: How to compile scss to css with node-sass

Alternatively, my approach involves using the run-watch tool nodemon:

npm install node-sass nodemon --save-dev

To proceed, add the following lines to your "scripts" section in package.json:

 "build-css": "node-sass --include-path scss src/input.scss src/styles.css",
 "watch-css": "nodemon -e scss -x \"npm run build-css\" "

Also, update your "start" script like this:

 "start": "concurrently \"node app.js\" \"npm run watch-css\" "

Furthermore, make sure to install the concurrently package:

npm install concurrently --save

Now, to compile and serve your files, just run:

npm start

In summary, running the "npm start" command initiates a build that launches the application and simultaneously triggers the "run watch-css" command, which then executes "build-css" for real-time compilation of scss to css via nodemon. This setup allows for seamless editing and live refreshing whenever you modify any scss file in your text editor.

Answer №2

Executing the command gulp will initiate the default task that is missing from your gulpfile. It is essential to incorporate it properly.

gulp.task('default', ['sass','watch']);

Answer №3

Avoid using gulp

  "start": "tsc && concurrently \"tsc -w\" \"lite-server\"  \"npm run build-css\"",
  "build-css": "node-sass resources/css/sass/style.scss resources/css/style.css",

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

Tips for avoiding HTTPS issues when communicating between Apache and Node Express servers

Recently, I repurposed an old laptop to run Ubuntu Server 18.04 and gave it a fixed IP address of 192.168.0.36 on my local network for easy SSH access from my main machine. This laptop is hosting a website written in React using the Apache server (built w ...

What is the best way to automatically connect npm packages during installation?

I am currently involved in a large project that is divided into multiple npm packages. These packages have dependencies on each other, and the entire code base is stored in a main directory structure like this: main/ pkg1/ pkg2/ ... For example, if ...

Enhancing the appearance of a JSX component in React

I have a segment of code within my project that calculates a specific percentage and displays it on the dashboard. <text className="netProfit-circle-text" x="50%" y="50%" dy=".2em" textAnchor="middl ...

How can I retrieve the value of a nested reactive form in Angular?

I'm working with a nested form setup that looks like this: profileForm = new FormGroup({ firstName: new FormControl(''), lastName: new FormControl(''), address: new FormGroup({ street: new FormControl(''), ...

"Enhance your project with the power of Angular CLI, npm,

I am working on an Angular 2 project built with npm and angular-cli. I want to be able to copy a folder into another folder before every compilation. The goal is to have multiple themes in individual folders, and then select one of those themes using a va ...

Sharing an angular app URL containing query parameters with multiple users

I am in need of a feature that allows me to transfer the filter settings on a page to another user. For instance, if I apply certain filters on a specific page, I would like to share the URL with those filters already applied to other users. ...

Quicker component refreshing in the Angular framework

Two Angular components were created, one for adding a new post and another for displaying all posts. Clicking the create post button redirects to the PostList component, which shows all posts. To automatically load the new post without manual refreshing, w ...

Are there any npm packages pre-installed in Azure functions? If there are, how can I verify their presence?

As I work on building my Azure function locally using WebStorm/PHPStorm, I am curious about if there are any pre-installed npm packages readily available in the cloud for Azure functions. It can be quite cumbersome to include all necessary packages each ...

Having trouble establishing a connection to MySQL through NodeJS and Express

I am currently attempting to establish a connection to MySQL using a nodeJS app with express as the server. I have referred to the mysql npm documentation to start the connection process, but I keep encountering an error in the callback function within cre ...

Angular Material Spinner with Custom Image Icons - (mat-spinner)

I have successfully implemented the mat-spinner in my project with configurable changes like color and mode of spinning. However, I am now looking to add an image icon, specifically the logo of a brand or company, inside the spinner. How can I achieve this ...

Limit the number of cards displayed per row using Angular Flexbox

I am currently working on a component that is supposed to display a maximum of x cards in each row, with the overflow (x+) scrolling in the horizontal direction. The challenge I am facing is getting exactly x cards to appear in one row, as shown in the ima ...

The inability to publish npm libraries on the repository is a common issue faced when using Npm in conjunction with Nexus Repository Manager 3

I am currently facing a challenge uploading npm libraries to a Nexus Repository Manager 3.1 that is located on a server without internet access. To work around this issue, I performed an npm install on a separate computer to obtain the necessary libraries ...

There has been an unhandled runtime error: [object ProgressEvent] occurring with Next.js/Typescript

Exploring the world of nextJS and typescript is new to me. I am currently working on creating a simple blog using nextJS/typescript with a sanity CMS backend. Everything seems to be running smoothly during development, but then I encounter this Unhandled R ...

Converting MongoDB data into a JavaScript array object

Hey there! I'm currently diving into learning MongoDB and Node.js. I recently managed to retrieve all collections of an order successfully, and below is the output: The orders: { __v: 0, nonmeat: 'pineapple', meat: 'Bacon', ...

Making strides in file uploads with formidable

For my backend using node.js-express with the formidable package, I attempted to integrate a progress bar utilizing formidable and websockets: const create = (req, res, io) => { logger.debug(`EXEC create material`) const form = new formidable.Incom ...

Discover how to access and manipulate JSON files in an Angular application using

Currently, I am diving into learning TypeScript with Angular and I'm interested in reading a JSON file. The structure of my JSON file is as follows: { "nb": "7", "extport": "1176",, "REQ_EMAIL": ...

Encounter a problem while running `ng build` due to a module not

I was looking to automate the building of my Angular project on a separate CentOS 7 machine. Here are the versions being used: Angular CLI: 8.3.23 Node: 13.14.0 OS: linux x64 Angular: 8.2.14 ... animations, common, compiler, compiler-cli, core, forms ... ...

Is it possible in Angular to directly bind the emitted output of a component to a property?

My primary application component communicates with its sub components using @Output decorated properties on the subcomponent. The output properties utilize an EventEmitter<>(). Typically, these properties emit a simple boolean or number. I want to di ...

Upgrade the VueJS project to utilize Node16

My Node JS version needs to be updated from 14.17.3 to 16.14.2, but when I run the project (created with node 14) using node 16, it throws this error: Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (93) ...

Encountering a npm issue - module.js 549 error message stating inability to locate npm-cli.js

After reinstalling nodejs, my npm started working again. However, after entering 3-4 commands in the command prompt (cmd) such as npm install nw-builder -g I encountered this error: module.js:549 throw err; ^ Error: Cannot find module &apos ...