Requires grunt 0.4. Use version 0.2.5 for grunt 0.3 compatibility
Grunt tasks to compile SCSS to CSS using node-sass
Check out grunt-contrib-sass (based on Ruby Sass) if you want something stable that also supports the old syntax
This task uses the experimental and superfast Node.js based Sass compiler node-sass (which only compiles .scss files).
Note that node-sass is currently under heavy development and might be unstable, there are also some stuff missing, like compression options and file/folder context, which means you need to specify @import using the relative path from your Gruntfile.
If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
npm install grunt-sass --save-dev
See the Gruntfile in this repo for a full example.
grunt.initConfig({
sass: { // Task
dist: { // Target
files: { // Dictionary of files
'main.css': 'main.scss', // 'destination': 'source'
'widgets.css': [ // Multiple sources will be concatenated
'button.scss',
'tab.scss'
]
}
},
dev: { // Another target
files: {
'main.css': 'main.scss',
'widgets.css': [
'button.scss',
'tab.scss',
'debug.scss' // Maybe you need one extra file in dev
]
}
}
}
});
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask('default', ['sass']);
grunt.initConfig({
sass: {
dist: {
files: {
'main.css': 'main.scss'
}
}
}
});
If you specify an array of src
paths they will be concatenated. However, in most cases you would want to just @import
them into main.scss
.
grunt.initConfig({
sass: {
files: {
'main.css': [
'reset.scss',
'main.scss'
]
}
}
});
You can also compile multiple files into multiple destinations.
grunt.initConfig({
sass: {
files: {
'main.css': 'main.scss',
'widgets.css': 'widgets.sass'
}
}
});
In lieu of a formal styleguide, take care to maintain the existing coding style.
MIT License (c) Sindre Sorhus