【问题标题】:Is Stylus render function Synchronous?Stylus 渲染功能是否同步?
【发布时间】:2015-01-20 15:27:36
【问题描述】:

我正在用它的 JavaScript API 编译我的 Stylus .styl 样式表:http://learnboost.github.io/stylus/docs/js.html

  var stylus = require('../')
    , str = require('fs').readFileSync(__dirname + '/test.styl', 'utf8');

  stylus(str)
    .set('filename', __dirname + '/test.styl')
    .import('mixins/vendor')
    .render(function(err, css){
    if (err) throw err;
    console.log(css);
  });

它没有提到它使用的回调是同步的还是异步的。虽然根据我的经验,它 似乎 是同步的,但我不确定。是吗?

【问题讨论】:

    标签: stylus


    【解决方案1】:

    render 函数是伪异步的,因为它接受回调,但函数内部的所有调用实际上都是同步的。这个函数还有一个完全同步的版本(如果你不提供回调):

    var styl = stylus(str)
      .set('filename', __dirname + '/test.styl')
      .import('mixins/vendor');
    
    console.log(styl.render()); // outputs compiled css
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-06
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 2018-11-24
      • 1970-01-01
      相关资源
      最近更新 更多