I have a project which is using a standard setup of using multiple sass files and partials which are compiled to a single global css file.
I now need the functionality to also have single sass files map to single css files (these are components/widgets).
So in my final markup a widget will have something like:
<link rel="stylesheet" href="css/main.css"/>
<link rel="stylesheet" href="css/widgets/widget-name.css"/>
I've tried a few options in my gruntfile. Current set up looks like this:
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
"Webcontent/css/site.css": "WebContent/source/sass/site.scss"
}
}
},
watch: {
src: {
files: ['WebContent/source/sass/*.scss'],
tasks: ['sass'],
}
}
I've tried the following:
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
"Webcontent/css/site.css": "WebContent/source/sass/site.scss",
"Webcontent/css/widgets/*.css": "WebContent/source/sass/widgets/*.scss",
}
}
},
As well as:
sass: {
dist: {
options: {
style: 'compressed'
},
files: [
{src: 'WebContent/source/sass/site.scss', dest: 'Webcontent/css/site.css'},
{src: 'WebContent/source/sass/widgets/*.scss', dest: 'Webcontent/css/widgets/*.css' },
],
}
},
watch: {
src: {
files: ['WebContent/source/sass/*.scss', 'WebContent/source/sass/widgets/*.scss'],
tasks: ['sass'],
}
}
I keep getting the error in grunt: Warning: Warning: Unable to write "Webcontent/css/widgets/*.css" file (Error code: ENOENT
).
Surely I don't have to specifiy a destination css file?
Any help much appreciated.
Based on your first solution and on http://ryanchristiani.com/getting-started-with-grunt-and-sass/, your "watched" files should more likely look like this:
(not sure if it really makes a difference, but better give it a try)
watch: {
src: {
files: 'WebContent/source/sass/*.scss',
tasks: ['sass'],
}
}
Otherwise, it is usually easier to build your Gruntfile.js this way:
(only main.scss is compiled and all the other .scss files are @import into this main.scss)
watch: {
sass: {
files: './assets/css/sass/*.scss',
tasks: ['sass', 'cssmin']
}
},
sass: require( './assets/custom_modules/sass.js' ).task,
cssmin: require( './assets/custom_modules/cssmin.js' ).task
Then in sass.js
exports.task = {
dist: {
options: {
style: 'expanded',
lineNumbers: true,
sourcemap: 'none'
},
files: [{
expand: true,
cwd: 'assets/css/sass/',
src: [ 'main.scss' ],
dest: 'assets/css/',
ext: '.css'
}]
}
};
Hope it could help.
Good Luck'
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