CSS 有 SASS.js 吗?像 LESS.js 之类的东西?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4436643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:18:52  来源:igfitidea点击:

Is there a SASS.js? Something like LESS.js?

csssassless

提问by Jiew Meng

I have used LESS.jsbefore. It's easy to use, something like

我已经使用LESS.js之前。它很容易使用,比如

<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?

我看到了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: { ... }}

采纳答案by chriseppstein

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.

没有官方认可的 sass 或 scss 的 JavaScript 实现。我已经看到了几个正在进行中的实现,但目前没有一个我可以推荐使用。

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

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.

因此,虽然开始需要更多的设置,但我们(sass 核心团队)认为服务器端编译是最好的长期方法。同样,较少的开发人员更喜欢生产样式表的服务器端编译。

回答by rodneyrehm

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.

由于 visionmeda/sass.js 不再可用,并且 scss-js 已经 2 年没有更新,我可能会对sass.js感兴趣。它是使用 Emscripten 编译为 JavaScript的 C++ 库libsass(也由node-sass使用)。可以在sass.link.js 中找到编译在 html 中链接或内联的 scss 样式表的实现。

Try out sass.js using the interactive playground

使用交互式游乐场试用 sass.js

回答by nikoloza

YES

是的

As we were expecting, after rewriting it on C++, it is possible to compile it in Javascript via Emscripten.

正如我们所期望的,在用C++重写之后,可以通过Emscripten在 Javascript 中编译它。

This is browser version: https://github.com/medialize/sass.js/

这是浏览器版本:https: //github.com/medialize/sass.js/

As they recommend, for node you can use this one: https://github.com/sass/node-sass

正如他们推荐的那样,对于节点,您可以使用这个:https: //github.com/sass/node-sass

回答by Chong Lip Phang

I just discovered an interesting Sass.js Playground. A few things may have changed over the years. Check this out:

我刚刚发现了一个有趣的 Sass.js Playground。这些年来,有些事情可能发生了变化。看一下这个:

http://medialize.github.io/playground.sass.js/

http://medialize.github.io/playground.sass.js/

回答by tilleryj

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?

您绝对不应该让所有用户都编译样式表,但是 javascript 实现也可以在服务器上运行。我也在寻找一个 javascript sass 实现 - 在 node.js 应用程序中使用。这是 sass 团队正在考虑的事情吗?

回答by Peter Lyons

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

GitHub 上有一个尝试,scss-js。但是,它是不完整的,并且在五个月内没有任何提交。

回答by John Slegers

Why LibSass

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

虽然没有官方认可的 sass 的 JavaScript 实现,但 Sass 引擎有一个官方的 C/C++ 端口,称为LibSass。因为 LibSass 是官方实现,所以最好选择一个在底层使用 LibSass 的 JavaScript 库。



On the server

在服务器上

For JavaScript running in a Node.js environment, there's Node-sass.

对于在 Node.js 环境中运行的 JavaScript,有Node-sass

Under the hood, Node-sass uses LibSass itself.

在底层,Node-sass 使用 LibSass 本身。



In the browser

在浏览器中

For JavaScript running in the browser, there's Sass.js.

对于在浏览器中运行的 JavaScript,有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.

在幕后,Sass.js 使用 LibSass 版本(在我撰写本文时为 v3.3.6),该版本已通过Emscripten转换为 JavaScript 。