npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp5-sass-plugin

v2.0.4

Published

Gulp plugin for sass

Downloads

747

Readme

gulp5-sass-plugin

CodeQL Test and coverage codecov

Sass plugin for gulp5.

Compare

We strongly recommend you to use this plugin instead of gulp-sass or gulp-dart-sass.

gulp-sass

gulp-sass is still using node-sass by default, and it has been deprecated for quite a long while.

Also, node-sass will take a long time to built during installation.

gulp-dart-sass

gulp-dart-sass is just forking the above project and changed it's deps, while it:

  • just remove sourcemap and pipe tests
  • still remain the old deps

gulp5-sass-plugin

It's a totally rewrite version in typescript. It has:

  • Uses new compile api
  • Option interface, and will provide autocomplete and validate (with IDE support like VSCode)
  • Code quality test and 100% test coverage

Install

pnpm add -D gulp5-sass-plugin
# or
yarn add -D gulp5-sass-plugin
# or
npm i -D gulp5-sass-plugin

Basic Usage

You should use sass to synchronously transform your sass code in to css:

import { dest, src, watch } from "gulp";
import { sass } from "gulp5-sass-plugin";

export const build = () =>
  src("./styles/**/*.scss")
    .pipe(sass().on("error", sass.logError))
    .pipe(dest("./css"));

export const watch = () => watch("./styles/**/*.scss", build);

You can also compile asynchronously:

import { dest, src, watch } from "gulp";
import { sassAsync } from "gulp5-sass-plugin";

export const build = () =>
  src("./styles/**/*.scss")
    .pipe(sassAsync().on("error", sassAsync.logError))
    .pipe(dest("./css"));

export const watch = () => watch("./styles/**/*.scss", build);

Error logging

Note that we provide a useful function called logError on these 2 transform functions to let you print errors gracefully.

See the demo above for usage.

Note that synchronous compilation is twice as fast as asynchronous compilation by default, due to the overhead of asynchronous callbacks. To avoid this overhead, you can use the fibers package to call asynchronous importers from the synchronous code path. To enable this, pass the Fiber class to the fiber option:

const { dest, src, watch } = require("gulp");
const { sass } = require("gulp5-sass-plugin");
const fiber = require("fibers");

const build = () =>
  src("./styles/**/*.scss")
    .pipe(sass({ fiber }).on("error", sass.logError))
    .pipe(dest("./css"));

exports.build = build;
exports.watch = () => watch("./styles/**/*.scss", build);

Options

You should pass in options just like you would for Dart Sass compileString api. They will be passed along just as if you were using sass. We also export SassOption and SassAsyncOption interface in declaration files.

For example:

export const build = () =>
  src("./styles/**/*.scss")
    .pipe(sass({ outputStyle: "compressed" }).on("error", sass.logError))
    .pipe(dest("./css"));

Or this for asynchronous code:

export const build = () =>
  src("./styles/**/*.scss")
    .pipe(
      sassAsync({ outputStyle: "compressed" }).on("error", sassAsync.logError),
    )
    .pipe(dest("./css"));

Source Maps

gulp5-sass-plugin can be used together with gulp-sourcemaps to generate source maps for the Sass to CSS compilation. You will need to initialize gulp-sourcemaps prior to running gulp5-sass-plugin and write the source maps after.

const { dest, src, watch } = require("gulp");
const { sassAsync } = require("gulp5-sass-plugin");
const sourcemaps = require("gulp-sourcemaps");

exports.build = () =>
  src("./styles/**/*.scss")
    .pipe(sourcemaps.init())
    .pipe(sassAsync({ outputStyle: "compressed" }).on("error", sass.logError))
    .pipe(sourcemaps.write())
    .pipe(dest("./css"));

By default, gulp-sourcemaps writes the source maps inline in the compiled CSS files. To write them to a separate file, specify a path relative to the gulp.dest() destination in the sourcemaps.write() function.

const { dest, src, watch } = require("gulp");
const { sassAsync } = require("gulp5-sass-plugin");
const sourcemaps = require("gulp-sourcemaps");

exports.build = () =>
  src("./styles/**/*.scss")
    .pipe(sourcemaps.init())
    .pipe(sassAsync({ outputStyle: "compressed" }).on("error", sass.logError))
    .pipe(sourcemaps.write("./maps"))
    .pipe(dest("./css"));

[!Warning] Currently we only support gulp-sourcemaps with sassAsync function.

Node Support

Since sass only supports Node.js 14 and above, we also only support Node.js 14 and above.

Issues

gulp5-sass-plugin is a very light-weight wrapper around Dart Sass. Because of this, the issue you're having likely isn't a gulp5-sass-plugin issue, but an issue with one those projects or with Sass as a whole.

If you have a feature request/question how Sass works/concerns on how your Sass gets compiled/errors in your compiling, it's likely a Dart Sass issue and you should file your issue with one of those projects.

If you're having problems with the options you're passing in, it's likely a Dart Sass and you should file your issue with one of those projects.

We may, in the course of resolving issues, direct you to one of these other projects. If we do so, please follow up by searching that project's issue queue (both open and closed) for your problem and, if it doesn't exist, filing an issue with them.