CSS 文件未使用 Windows 中的节点-sass 生成

CSS file not generating using node-sass in Windows

我正在使用 node-sasssass 文件转换为 css 但不知何故它没有在文件夹中创建 css 文件。请帮我解决我在代码中做错了什么。

我的文件夹结构是这样的-

我在 css 文件夹中有一个 main.scss 文件。

我的index.js代码是-

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);
});

虽然控制台中没有错误,但 css 文件也没有在 CSS 文件夹中生成。让我知道我在这里做错了什么。

仅供参考 - 这是控制台中的结果输出。

编辑 1

我将 index.js 文件的代码更改为以下但仍然无法正常工作 -

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).

因此您需要手动将输出写入磁盘:

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
        }
      });
    }
  });
});