有 SASS.js 吗?像 LESS.js 这样的东西?
我之前使用过 LESS.js 。它很容易使用,就像
<link rel="stylesheet/less" href="main.less" type="text/css">
<script src="less.js" type="text/javascript"></script>
我看到的 SASS.js 一样。我怎样才能以类似的方式使用它?解析 SASS 文件以便立即在 HTML 中使用。看起来 SASS.js 更适合与 Node.js 一起使用?
var sass = require('sass')
sass.render('... string of sass ...')
// => '... string of css ...'
sass.collect('... string of sass ...')
// => { selectors: [...], variables: { ... }, mixins: { ... }}
I have used LESS.js before. It's easy to use, something like
<link rel="stylesheet/less" href="main.less" type="text/css">
<script src="less.js" type="text/javascript"></script>
I saw SASS.js. How can I use it in a similar way? Parsing a SASS file for use immediately in HTML. It seems like SASS.js is more for use with Node.js?
var sass = require('sass')
sass.render('... string of sass ...')
// => '... string of css ...'
sass.collect('... string of sass ...')
// => { selectors: [...], variables: { ... }, mixins: { ... }}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
sass 或 scss 没有官方认可的 JavaScript 实现。我已经看到了一些正在进行中的实现,但目前我不建议使用。
但是,请注意几点:
因此,虽然开始需要更多的设置,但我们(sass 核心团队)认为服务器端编译是最好的长期方法。同样,越来越少的开发人员喜欢使用服务器端编译来生成样式表。
There is no officially sanctioned JavaScript implementation of sass or scss. There are a couple of implementations in progress that I've seen, but none that I can recommend using at this time.
However, please a few points:
So while it's a little more setup to get started, we (the sass core team) think that server side compilation is the best long term approach. Similarly, the less developers prefer server side compilation for production stylesheets.
由于visionmeda/sass.js 不再可用,并且 scss-js 已经有 2 年没有更新了,我可能会对 感兴趣sass.js。它是 C++ 库 libsass (也被 node-sass) 使用 Emscripten 编译为 JavaScript。编译在 html 中链接或内联的 scss 样式表的实现可以在 sass.link.js 中找到。
使用交互式游乐场尝试 sass.js
Since visionmeda/sass.js isn't available anymore and scss-js hasn't been updated in 2 years, I might interest you in sass.js. It's the C++ library libsass (also used by node-sass) compiled to JavaScript using Emscripten. An implementation to compile scss stylesheets linked or inlined in html can be found at sass.link.js.
Try out sass.js using the interactive playground
YES
正如我们所期望的,在C++上重写后,可以通过 Emscripten 在 Javascript 中编译它。
这是浏览器版本: https://github.com/medialize/sass.js/
作为他们建议,对于节点,您可以使用这个: https://github.com/sass/node-sass< /a>
YES
As we were expecting, after rewriting it on C++, it is possible to compile it in Javascript via Emscripten.
This is browser version: https://github.com/medialize/sass.js/
As they recommend, for node you can use this one: https://github.com/sass/node-sass
我刚刚发现了一个有趣的 Sass.js Playground。这些年来,有些事情可能已经发生了变化。看看这个:
http://medialize.github.io/playground.sass.js/
I just discovered an interesting Sass.js Playground. A few things may have changed over the years. Check this out:
http://medialize.github.io/playground.sass.js/
您绝对不应该让所有用户都编译样式表,但是 JavaScript 实现也可以在服务器上运行。我也在寻找 javascript sass 实现 - 在 node.js 应用程序中使用。这是sass团队正在考虑的事情吗?
You definitely shouldn't make all of your users compile stylesheets, however a javascript implementation can run on the server as well. I'm also looking for a javascript sass implementation - to use in a node.js app. Is this something the sass team is considering?
在 GitHub 上进行了尝试,scss-js。然而,它并不完整,并且五个月内没有任何提交。
There is an attempt on GitHub, scss-js. However, it is incomplete and hasn't had any commits in five months.
为什么选择 LibSass
虽然没有官方认可的 sass JavaScript 实现,但 Sass 引擎有一个官方 C/C++ 端口,称为 LibSass。由于 LibSass 是官方实现,因此最好选择在底层使用 LibSass 的 JavaScript 库。
在服务器上
对于在 Node.js 环境中运行的 JavaScript,有 Node-sass< /a>.
在底层,Node-sass 使用 LibSass 本身。
在浏览器中
对于在浏览器中运行的 JavaScript,有 Sass.js。
在底层,Sass.js 使用 LibSass 版本(在我撰写本文时为 v3.3.6),该版本已通过 Emscripten。
Why LibSass
While there is no officially sanctioned JavaScript implementation of sass, there is an official C/C++ port of the Sass engine, known as LibSass. Because LibSass is an official implementation, it's best to opt for a JavaScript library that uses LibSass under the hood.
On the server
For JavaScript running in a Node.js environment, there's Node-sass.
Under the hood, Node-sass uses LibSass itself.
In the browser
For JavaScript running in the browser, there's Sass.js.
Under the hood, Sass.js uses a version of LibSass (v3.3.6 at the point of my writing this) that's been converted to JavaScript with Emscripten.