I am using node-sass
to convert sass
files to css
but somehow its not creating css file in a folder. Please help me out with what I am doing wrong with the code.
My Folder structure is like -
And I have a main.scss
file in css
folder.
My index.js
code is -
var fs = require('fs');
var sass = require('node-sass');
sass.render({
file: './css/main.scss',
outFile: './css/main.css',
}, function(err, result) {
if(err)
throw err;
console.log(result);
});
Though no error is thrown in the console but the css file is also not generating in CSS
folder. Let me know what I am doing wrong here.
FYI - Here is the result output in console.
EDIT 1
I changed the code of index.js file to the following but still not working -
var fs = require('fs');
var sass = require('node-sass');
sass.render({
file: './css/main.scss',
outFile: 'css',
}, function(err, result) {
if(err)
throw err;
fs.writeFile(__dirname + '/css/', 'main.css', function(err){
if(!err){
//file written on disk
}
});
});
Checkout the node-sass docs for outFile:
Specify the intended location of the output file. Strongly recommended when outputting source maps so that they can properly refer back to their intended files.
Attention enabling this option will not write the file on disk for you, it's for internal reference purpose only (to generate the map for example).
So you need to manually write the output to disk:
sass.render({
...
outFile: yourPathTotheFile,
}, function(error, result) { // node-style callback from v3.0.0 onwards
if(!error){
// No errors during the compilation, write this result on the disk
fs.writeFile(yourPathTotheFile, result.css, function(err){
if(!err){
//file written on disk
}
});
}
});
});