Gulp is a toolkit to automate & enhance our workflow. Most of the time, I use gulp for my SASS projects. In this article, I’ll show you how to use gulp
to automate SASS to CSS compilation.
First, let’s create a folder named sass
and then initialize npm
inside the folder.
npm init
Once we’ve our package.json
file is ready. We can install the gulp
using this command :
npm install --save-dev gulp
Now, we install the other dependencies we’ll use.
npm install sass gulp-sass --save-dev
As we’ve everything installed. It’s time to create gulpfile.js
. Then, we’ll add the task compile
in the gulpfile.js
, which will compile our SASS.
let {gulp, watch, series, src, dest} = require('gulp');
let sass = require('gulp-sass')(require('sass'));
function compileSassFiles(done) {
src("sass/*.scss")
// Apply sass on the files found
.pipe(sass())
// Log errors from the sass
.on("error", sass.logError)
// Destination for the compiled file(s)
.pipe(dest("css"));
done();
}
exports.compile = function (done) {
watch(
'sass/**/*.scss',
{
ignoreInitial: false
},
compileSassFiles
);
}
Notice that, the task will watch for changes in any .scss
files, including the files inside sub-directories of sass folder.
Now as we’ve our task is ready, we just have to run it in the terminal :
gulp compile
We’re done! Keep the terminal open, and you’re ready to automate SASS to CSS compilation!
To open the side panel by default in google Chrome extension, you can use the…
Today I will share a snippet I've used in a project. Using that function, you…
JavaScript AJAX (Asynchronous JavaScript and XML) is a technique that gives the ability to send…
By default, Bootstrap carousel has no way to add animations to carousel elements. Here I'm…
Laravel comes up with a paginator that generates HTML compatible with the Tailwind CSS framework.…
Bootstrap introduced their icons collection in November 2019 as Bootstrap Icons (v1.0.0-alpha). At that time,…