Compiling node-sass takes 10 minutes
Asked Answered
H

4

14

We operate many small websites. We usually host them on Digital Ocean's $5-$10 servers.

Part of our deployment is compiling of Sass to CSS using node-sass.

On our latest server we experience a significant increase in compiling time for node-sass library (not the actual scss files). We're talking about 8-10 minutes, where in other projects it takes 30sec - 100sec.

We use node 8.11.1 (newest LTS) and yarn 1.6.0 (newest) with node-sass 4.8.3 (newest) on Ubuntu 16.04.4.

Is there any way to cache the compilation between deployments? Or is anyone aware why its taking so much time to compile node-sass?

Historiographer answered 20/4, 2018 at 9:10 Comment(7)
How the compilation is triggered? Are the node_modules cached or must install everytime?Katherine
It is triggered by yarn install -- yeah node_modules are installed fresh with every deployment.Historiographer
Why not yarn install —production so you don’t need to install dependencies everytime? How the command is triggeder? Do you have a deploy set or it is manually?Katherine
Actually it is indeed triggered with the production flag. We have a deploy script: Create folder, pull from git, install dependencies, run build scripts, switch folders -- released.Historiographer
Maybe you could create some verbose log output so you could take a look at which process is taking so long. I faced npm installs with the virtual host that taked way too much to install. I solved that installing all the node packages as root, so the virtual host user only used the desired method, and never have to install the node packages.Katherine
It's the node-sass compilation taking so long, yarn states: node-sass: g++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_LARGEFILE_ ... and so onHistoriographer
Is there any imports using url in you sass files?Katherine
H
8

If someone finds this through search engine:

We did not find any solution for the issue. We scaled the droplet up and down back to it's original size and the problem was gone.

Historiographer answered 10/10, 2018 at 0:11 Comment(0)
F
3

If you're running a supported OS and Node combination (see the release page on GH for your version of node-sass), the pre-built binary should be downloaded for you.

Ferreira answered 28/4, 2018 at 2:54 Comment(0)
C
0
npm install

yarn has some issues with caching (could be on your PC, or on CDN). That could lead to huge time increase if you have a few node version on your PC (e.g. nvm). In my case installing dependencies with npm worked: 40 seconds, compared to 5+ minutes with yarn (I didn't wait till the end)

Chrominance answered 8/7, 2019 at 17:47 Comment(0)
W
0

I ran into this after working on a site first on my Mac Mini then on my PC. I had this:

const sassCompiler = require('gulp-sass')(require('sass'));

On the Mac it worked decently, perhaps the M1, but on my PC which is a few years old but high-end, it took around a minute for every CSS change.

I checked the docs and the second parameter (require('sass')) indicates the compiler and that the main two options are sass and node-sass.

Since I am using Yarn I did yarn add node-sass to my project. Then modified my gulpfile line to this:

const sassCompiler = require('gulp-sass')(require('node-sass'));

The difference is tenfold.

With SASS compiler: With SASS

With Node-SASS compiler: With Node-SASS

I still haven't tried the new config on my Mac, but I don't think there would be a big difference.

Whereof answered 21/12, 2022 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.