GithubHelp home page GithubHelp logo

Comments (5)

mcsagittarius avatar mcsagittarius commented on August 23, 2024

Hmm... after a nights rest I've come up with a better solution.

I also had issues with grunt-watch. Since the "localObj" cache was set on the first run, it would simply not include any files on subsequent runs, since the files were already in the cache.

So, my solution for getting this to work with grunt and grunt-contrib-watch is:

  1. Require module as normal.
  2. Setup an options object e.g. importOnce: { options: {} } somewhere in the grunt.config tree.
  3. Create anonymous function as importer in your "node-sass" task options.
  4. Call the required importOnce with your options object passed as scope.
  5. Setup an event listener for the "watch" event and reset the options object to empty (or whatever options you initially had).

Simplified example of Gruntfile.js:

var importOnce = require("node-sass-import-once");
grunt.initConfig({
    importOnce: { options: {} },
    sass: {
        options: {
            ...,
            importer: function (uri, prev, done) {
                importOnce.call(grunt.config.data.importOnce, uri, prev, done);
            },
            ...
        },
        ...
    },
    watch: {
        scss: {
            files: ["/scss/**/*.scss"],
            tasks: ["sass"],
            options: {
                ...
            }
        }
    }
    grunt.event.on("watch", function (action, filepath) {
        grunt.config(["importOnce"], { options: {} });
    });
});

I hope this will help others who are having trouble getting this to work with grunt.

Cheers.

from node-sass-import-once.

mcsagittarius avatar mcsagittarius commented on August 23, 2024

I'm closing this as it can be resolved externally. Please consider updating the readme with some of my findings (or something better?).

from node-sass-import-once.

Snugug avatar Snugug commented on August 23, 2024

The error you're getting is most likely because you're not using the Node Sass >= v3.0.0-alpha.5, which is explicitly required in order to use the importer.

from node-sass-import-once.

Snugug avatar Snugug commented on August 23, 2024

That, or grunt-sass is doing something super crazy weird with the way it passes options to Node Sass

from node-sass-import-once.

mcsagittarius avatar mcsagittarius commented on August 23, 2024

I'm using the latest version of grunt-sass which requires "node-sass": "^3.0.0-", so that's probably it.

Other grunt-users will likely be in the same situation until it's updated though.

Thanks.

EDIT:

Hmm... just checked the version of node-sass that grunt-sass installs and it's @2.1.1, but the node-sass repo says:

"importer (>= v2.0.0) - experimental"

So, node-sass 2.1.1 still supports this feature (experimentally) which, I suppose, is why I can still get it to work.

from node-sass-import-once.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.