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

grunt-sass-modern

v3.3.0

Published

Compile Sass to CSS using dart-sass

Downloads

112

Readme

grunt-sass-modern

Compile SASS to CSS using Dart Sass

npm Total Monthly License

This is a fork of the original grunt-sass repository which required a small update as per this issue after Dart SASS started emitting the following deprecation warning starting with version 1.79.0:

Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0. More info: https://sass-lang.com/d/legacy-js-api

Since the author of the original repository did not provide a fix and still a lot o projects are relying on it, a fix was created by Matt Robinson via this commit, and I decided to fork the main repository, add the fix to it and also update this page about what you can do to properly update your code and not just silence the warning.

This version also fixes broken source map generation which was not working in the original grunt-sass since probably Dart Sass version 1.48.0 but I can't tell for sure the version where it broke - please let me know if you know better.

Install

If you are already using the original grunt-sass, edit your package.json file and look for something like

"grunt-sass": "^3.1.0",

...and delete that.

Afterwards, call

$ npm install --save-dev grunt-sass-modern

...to install the updated version

Usage

In your Gruntfile.js, in the sass section, you need to add the api entry to the options part, and set its value to "modern":

module.exports = function(grunt) {

    const sass = require('sass');

    grunt.initConfig({
        sass: {
            options: {
                implementation: sass,
                sourceMap: true,    // broken in "grunt-sass" for versions of SASS newer than 1.48.0
                api: 'modern'       // this is required starting with Dart-Sass 1.79.0
                                    // (and only working with grunt-sass-modern)
            },
            dist: {
                files: {
                    'destination.css': 'source.scss'
                }
            }
        }
    });

    // remember to also update this from "grunt-sass" to "grunt-sass-modern"!
    grunt.loadNpmTasks('grunt-sass-modern');
    grunt.registerTask('default', ['sass']);

}

Silencing the warning

If for whatever reason you are not able to update your code and you just want to silence the warning as in the example below

module.exports = function(grunt) {

    const sass = require('sass');

    grunt.initConfig({
        sass: {
            options: {
                implementation: sass,
                sourceMap: true,
                silenceDeprecations: ['legacy-js-api']	// this is needed in order to silence the deprecation warning
            },
            dist: {
                files: {
                    'destination.css': 'source.scss'
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-sass-modern');
    grunt.registerTask('default', ['sass']);

}

Heads-up regarding the sourceMap attribute

Note that in the original repo, sourceMap generation is broken and it is fixed in grunt-sass-modern.

The caviat is that the newer versions of Sass do not add a sourceMappingURL comment to the generated CSS by default!

Excerpt from their docs:

Sass doesn't automatically add a sourceMappingURL comment to the generated CSS. It's up to callers to do that, since callers have full knowledge of where the CSS and the source map will exist in relation to one another and how they'll be served to the browser.

grunt-sass-modern fixes this by automatically adding the sourceMappingURL comment to your compiled CSS, and making the sourceMap option work as it used to in legacy mode of Sass:

module.exports = function(grunt) {

    const sass = require('sass');

    grunt.initConfig({
        sass: {
            options: {
                implementation: sass,

                // use it like this to create the map where destination.css resides
                // (and write the sourceMappingURL comment in to the destination.css)
                sourceMap: true,

                // use it like this to create the map at given path
                // (and write the sourceMappingURL comment in to the destination.css)
                sourceMap: 'path/to/map',

                files: {
                    'destination.css': 'source.scss'
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-sass-modern');
    grunt.registerTask('default', ['sass']);

}

Options

See the Dart Sass options.

For more information please refer to the original grunt-sass repository.