I am trying to compile multiple .scss files into a single CSS file. This actually works but only grabs the first file...
sass: { // Task
dist: {
files: {
'css/test.css':'sass/*.scss'
}
}
}
We don't have ruby installed so grunt-contrib-sass is not an option. I do the same thing in Stylus like this...
stylus: {
compile : {
files : {
'css/g.css' : 'stylus/*.styl'
}
}
}
What about running grunt-contrib-concat
first?
concat: {
dist: {
src: [
'sass/*.scss',
],
dest: 'sass/build.scss',
}
},
sass: { // Task
dist: {
files: {
'css/test.css':'sass/build.scss'
}
}
}
and then task:
grunt.registerTask('sass', ['concat', 'sass']);
edit
How are you using @import
? I'm not an expert on the specifics, but here is what I do...
dir/
main.scss
_nav.scss
_vars.scss
etc.
main.scss
@import "nav";
@import "vars";
etc.
I just want to touch on this, because I had the same issue, and this will actually work:
sass: { // Task
dist: {
files: [{
// Set to true for recursive search
expand: true,
cwd: 'scss/',
src: ['**/*.scss'],
dest: 'css/',
ext: '.css'
}]
}
}
Let me know how it goes!
You can use "grunt-sass-globbing". It will generate a SCSS file with all the imports you specified in your Gruntfile. https://www.npmjs.com/package/grunt-sass-globbing/
With this option you can keep your source maps and you don't need to concatenate your SCSS files.
sass_globbing: {
your_target: {
options: {
useSingleQuotes: false,
signature: '// Hello, World!'
},
files: {
'imports.scss': 'partials/**/*.scss',
}
}
}
sass: {
options: {
sourceMap: true
},
develop: {
files: {
'main.css': 'imports.scss'
}
}
}
If you don't wanna use concat, you can specify all files in directory. Checkout this example: https://github.com/gruntjs/grunt-contrib-sass#compile-files-in-a-directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With