In development, recompiling .css every time .styl changes is highly convenient. But on production, we don't want to spend resources compiling on every request; we'd like to compile once, on app start.
Can Stylus be configured this way?
In development, recompiling .css every time .styl changes is highly convenient. But on production, we don't want to spend resources compiling on every request; we'd like to compile once, on app start.
Can Stylus be configured this way?
SocketStream有一个资产打包器,可以在生产模式下预编译 css、js 和模板文件。也许使用检查环境变量(开发或生产)的模式,然后提供即时编译的文件集,或在节点第一次启动时完成的预打包资产集(即编译你的css,然后使用fs
模块将它们写入磁盘)。
以下内容来自socketstream的stylus模块:
stylus(input, {filename: path, paths: [dir.join('/')]})
.render(function(err, css) {
if (err) {
console.log(err);
}
cb(css);
});
cb 方法是用于提供fs.writeFileSync调用的回调,该调用接收已编译的文件。所以,最后你有 4 个部分: