有 SASS.js 吗?像 LESS.js 这样的东西?

发布于 2024-10-07 04:32:22 字数 736 浏览 3 评论 0原文

我之前使用过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

时光无声 2024-10-14 04:32:22

sass 或 scss 没有官方认可的 JavaScript 实现。我已经看到了一些正在进行中的实现,但目前我不建议使用。

但是,请注意几点:

  1. 当您可以为所有用户编译一次样式表时,为什么要让所有用户编译样式表。
  2. 如果禁用 JavaScript,您的网站会是什么样子。
  3. 如果您决定将来更改为服务器端实现,则所有模板都必须相应更改。

因此,虽然开始需要更多的设置,但我们(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:

  1. Why should you make all your users compile your stylesheets when you can do it once for all of them.
  2. What would your site look like if JavaScript is disabled.
  3. If you decide to change to a server-side implementation at a future time, all your templates must be changed accordingly.

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.

寄意 2024-10-14 04:32:22

由于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

听闻余生 2024-10-14 04:32:22

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

最后的乘客 2024-10-14 04:32:22

我刚刚发现了一个有趣的 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/

成熟的代价 2024-10-14 04:32:22

您绝对不应该让所有用户都编译样式表,但是 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?

绿光 2024-10-14 04:32:22

GitHub 上进行了尝试,scss-js。然而,它并不完整,并且五个月内没有任何提交。

There is an attempt on GitHub, scss-js. However, it is incomplete and hasn't had any commits in five months.

吻泪 2024-10-14 04:32:22

为什么选择 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文