Comments (5)
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:
- Require module as normal.
- Setup an options object e.g. importOnce: { options: {} } somewhere in the grunt.config tree.
- Create anonymous function as importer in your "node-sass" task options.
- Call the required importOnce with your options object passed as scope.
- 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.
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.
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.
That, or grunt-sass
is doing something super crazy weird with the way it passes options to Node Sass
from node-sass-import-once.
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)
- importing .js files as modules rather than parsing contents as JSON HOT 10
- Dot in filenames cause errors HOT 2
- Automatic import of node_modules HOT 5
- Better default to true for most options HOT 1
- add 'alias' option HOT 2
- globbing solution HOT 3
- Multiple failures with node-sass 3.4.1 HOT 5
- Hierarchy and import HOT 1
- Doesn't seem to see the files when referenced without underscore at beginning + file extension. HOT 4
- Doesn't work on OSX HOT 2
- Split into multiple modules HOT 3
- extract-text-webpack-plugin HOT 5
- sass.renderSync use 'importOnce' option error HOT 1
- Parse sass on import
- Does not work together with option `includePaths`? HOT 1
- Better usage instructions for gulp
- Does not stop CI build if Could not import error HOT 2
- Not compatible with Yarn 2 (PnP)
- Doesn't work with gulp: this is undefined HOT 3
- _index.scss is bad DX. Add partials/_partials.s[ca]ss lookup. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-sass-import-once.