【问题标题】:Stylus.set() not updating the output.Stylus.set() 不更新输出。
【发布时间】:2015-12-23 06:35:07
【问题描述】:

我想在我的手写笔中访问 javascript 值,我在下面这样做。此函数完美地输出值,但它没有更新我的 test.css 文件。

var config = {
    sizes:{
        width:"500px",
    height:"200px"
    },
  background:"rgba(10,10,100)",
  color:[100,10,10,.5],
    someArray:[100,0,0,2]
};

var str = require('fs').readFileSync(__dirname+'/test.styl',{encoding:'utf8'});

var stylus = require('stylus');

var stylusVars = require('stylus-vars')(config,{delimiter:'-'});
// the delimiter option defines how nested objects will be represented

stylus(str)
    .set('filename','test.css')
    .use(stylusVars)
    .render(function(err, css){
        if(err){throw err;}
        console.log(css);
});

stylus.set() 有什么作用?

【问题讨论】:

  • 不应该写文件吗? fs.writeFile('test.css', css)

标签: javascript css stylus


【解决方案1】:

您应该将结果 css 写入带有 fs.writeFileSync('test.css', css); 的文件,而不是通过 console.log 输出。 .set 只是一种设置手写笔选项的方法(在您的情况下为filename,需要此选项来解析@importstatements 中的相对路径)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2017-09-03
    • 2020-08-17
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多