【问题标题】:compile css on the fly with node-sass使用 node-sass 即时编译 css
【发布时间】:2015-12-15 17:59:57
【问题描述】:

我正在尝试为我的 scss 文件构建一个即时编译器。 逻辑是: - 当页面询问节点或 .css 文件时 - 看看哪个子域正在调用 - 编译css:

var result = sass.renderSync({
    file: org+'/css/sass/main.scss',
    outputStyle: 'compressed'
});
return res.send(result.css);

一切都“正常”,因为我得到了带有所有已编译样式表的 result.css(对象),但是......它没有从浏览器加载!

我做错了什么?

【问题讨论】:

    标签: node-sass


    【解决方案1】:

    我安装了 node-sass 模块来编译 scss 文件,cleancss 最小化,然后我修复了在发送结果之前设置标题的问题。

        var result = sass.renderSync({
            file: org+'/css/sass/main.scss'
        });
        result = new cleancss().minify(result.css);
        res.setHeader('Content-Type', 'text/css');
        return res.send(result.styles);
    

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2013-03-18
      • 1970-01-01
      • 2020-05-28
      • 2021-11-08
      • 2015-10-05
      • 1970-01-01
      • 2020-12-09
      • 2023-04-04
      相关资源
      最近更新 更多