将 SASS 与 ASP.NET 结合使用
我正在研究使用 SASS (语法很棒的样式表)的方法ASP.NET 环境中的 Ruby HAML 包。 理想情况下,我希望将 SASS 文件编译成 CSS 成为构建过程的无缝部分。
这种集成的最佳方法是什么? 或者,是否还有其他更适合 .NET 环境的 CSS 生成工具?
I'm looking into ways to use SASS (Syntactically Awesome StyleSheets) from the Ruby HAML package in an ASP.NET environment. Ideally, I would like compilation of SASS files into CSS to be a seamless part of the build process.
What are the best ways to this integration? Alternatively, are there other CSS-generation tools that are better suited for a .NET environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
为了在 Visual Studio 中获得更好的工作体验,您可以安装开始支持 Sass (SCSS) 的最新版本 Web Essential句法)。
或者,您可以安装 Sassy Studio 或 网络工作台。
然后,要在 ASP.NET 项目中编译 .sass/.scss 文件,可以使用一些不同的工具:通过 Web Essential , Web 工作台, SassC,Sass.Net,指南针,SassAndCoffee ...
Web Essential 一个功能齐全的 Visual Studio 插件,确实提供了更好的体验对于所有前端的东西。 最新版本开始支持Sass(SCSS语法)。 它在内部使用 Libsass 将 SCSS 编译为 CSS。
Web Workbench 是 Visual Studio 的另一个插件,可添加语法突出显示、智能和其他一些用于编辑 SCSS 文件的有用的东西。 它还可以将您的代码编译为普通或缩小的 CSS。 它在内部使用了 Ruby Sass 编译器的包装版本。
Sassy Studio:另一个插件视觉工作室。 功能较少但更轻。
Libsass 库 是 Sass CSS 预编译器的 C++ 端口(仍在开发中) 。 最初的版本是用 Ruby 编写的,但这个版本是为了提高效率和可移植性。 该库力求轻量、简单、易于构建并与各种平台和语言集成。
Libsass 库有几个包装器:
Compass 是一个 Sass 框架,它添加了许多有用的帮助器(例如图像精灵),还可以编译您的 SCSS/Sass。 但是您需要在需要编译样式的每个开发环境上安装 Ruby。
SassAndCoffee 是一个添加 SCSS/Sass 编译和缩小支持的包,通过一些DLL 和配置。 与 Web Workbench 编译器相比,它的优势在于它独立于您的 Visual Studio 解决方案:您不需要在每个开发环境上安装插件。 备注:SassAndCoffee 不经常更新,并且因为它使用 IronRuby 来包装官方 Ruby 编译器,所以您可能会遇到一些性能问题。 您可以通过 Nuget 包 安装最新版本。
For a better working experience in Visual Studio, you could install the last version of Web Essential which is starting to support Sass (SCSS syntax).
Alternatively you could install Sassy Studio or Web Workbench.
Then to compile your .sass/.scss files in your ASP.NET project, there is some different tools: via Web Essential, Web Workbench, SassC, Sass.Net, Compass, SassAndCoffee...
Web Essential a fully featured plugin for Visual Studio, which really give a better experience for all Front-End stuffs. The latest version is starting to support Sass (SCSS syntax). Internally it use the Libsass to compile the SCSS to CSS.
Web Workbench is another plugin for Visual Studio that add syntax highlighting, intellisence and some other useful stuff for editing SCSS files. It can also compile your code into normal or minified CSS. Internally it used a wrapped version of the Ruby Sass compiler.
Sassy Studio: another plugin for Visual Studio. Less featured but much lighter.
The Libsass library is C++ port of the Sass CSS precompiler (still in development). The original version was written in Ruby, but this version is meant for efficiency and portability. This library strives to be light, simple, and easy to build and integrate with a variety of platforms and languages.
There are several wrappers around the Libsass library:
Compass is a framework for Sass that add a lot of useful helpers (like image spriting) and can also compile your SCSS/Sass. But you need to install Ruby on each development environment where you need to compile your styles.
SassAndCoffee is a package that adds SCSS/Sass compilation and minification support, via some DLLs and configs. Its advantage over the Web Workbench compiler is it's self-contained into your Visual Studio solution: you don't need to install a plugin on every development environment. Remark: SassAndCoffee is not often updated, and because it use IronRuby to wrap the official Ruby compiler, you can get some performance issues. You can install the latest version via a Nuget package.
compass 项目有一个编译器,可以将 sass 编译为 css。 它是为在 Windows 上运行而构建的,但在该平台上尚未经过充分测试。 如果您发现任何与平台相关的错误,我很乐意帮助您修复它们。
指南针可以在这里找到:http://github.com/chriseppsein/compass
The compass project has a compiler that will compile your sass to css. It's built to run on windows, but it is not well tested on that platform. If you find any platform related bugs, I'll gladly help you fix them.
Compass can be found here: http://github.com/chriseppsein/compass
2015 年,我当前的建议是使用
Node.js
(服务器端 Javascript 平台)和gulp.js
(任务运行器节点包),以及gulp-sass
(用于 gulp 实现 libsass 的节点包 - Ruby SASS 的快速 C 端口)。您可以使用这样的教程开始使用。
这就是为什么我认为你应该使用 Node 和 Gulp。
许多 Web 开发人员现在都使用 Node 这个平台来完成前端 Web 开发任务。 无论是 Grunt、Gulp、JSPM、Webpack 还是其他东西 - 它现在都在 npm 中发生。
你可以使用 npm 包做的事情:
设置好项目
package.json
和gulpfile.js
后,通常只需执行几个步骤即可开始运行:npm install -g gulp
(全局安装gulp)npm install
(在本地安装项目包)gulp taskname
(根据您如何设置gulpfile.js
taskname 将运行编译 SASS、Javascript 等的任务)< /em>不管你相信与否,VS2015 现在可以为你处理所有命令行的东西!
在工作流程方面,您有几个典型的选项:
让您的开发人员将其编译的代码提交到存储库
缺点:开发人员必须始终运行
gulp
或类似工具来编译可用于生产的资产您的构建|阶段|生产服务器在发布之前运行 gulp 任务
这种方式设置起来可能比较复杂,但意味着工作是经过验证的,并且是从未编译的源代码构建的。
以下是我 2012 年的旧答案,为后代保留:
In 2015, my current advice is to use
Node.js
(Server-side Javascript platform) andgulp.js
(a task runner node package), along withgulp-sass
(a node package for gulp implementing libsass - a fast C port of Ruby SASS).You can get started with a tutorial like this.
Here's why I think you should use Node and Gulp.
Many web developers are now using Node a platform for frontend web development tasks. Whether it's Grunt, Gulp, JSPM, Webpack, or something else - it's happening right now in npm.
Things you can do with npm packages:
Once you've set up your project
package.json
andgulpfile.js
, all it usually takes to get running is a few steps:npm install -g gulp
(installs gulp globally)npm install
(installs project packages locally)gulp taskname
(Depending on how you've set up yourgulpfile.js
taskname will run a task that compiles your SASS, Javascript etc)Believe it or not, VS2015 can now handle all the commandline stuff for you!
You have a couple of typical options in terms of workflow:
Have your developers commit their compiled code to the repository
Downside: Developers must always run
gulp
or similar to compile production-ready assetsYour build|stage|production servers run gulp tasks before releases
This way can be more complicated to set up, but means that work is validated and built fresh from uncompiled source.
Below is my old answer from 2012, kept for posterity:
我刚刚编写了一个 Visual Studio 插件,其中包含详细说明,包括有关如何将 Sass 用于 Visual Studio 的屏幕截图。 在这里查看 - http://giri.sh/2011/01/21/ sass-for-visual-studio-2010/
I just wrote a Visual Studio Add-in with detailed instructions including screenshots on how to get Sass going for Visual Studio. Check it out here - http://giri.sh/2011/01/21/sass-for-visual-studio-2010/
它不是 SASS,但您可以查看我们的 Less Css for .NET 端口。 不过 Compass 看起来真的很有趣,我认为像 Less 这样的东西会是一个很好的补充。
Its not SASS but you could take a look at our Less Css for .NET port. Compass looks really interesting though, and I think something like this for Less would be a great addition.
我昨天才发现这个,它看起来很有前途,除了 sass/scss 之外,它还能处理 JS(还不是 CSS)的自动压缩和文件组合。 我希望有人能够创建一个 VS 插件来编辑 sass/scss 文件。 我确实发现有问题的是,当您的 sass/scss 代码出现错误时,您只会发现它正在测试或检查生成的 CSS 文件。 我还没有完成所有的步骤,但到目前为止还不错。
https://github.com/xpaulbettsx/SassAndCoffee
I just found this yesterday, it looks quite promising, aside from sass/scss it will handle autominification of JS (not CSS - yet) and combining of files. One thing that I'm hoping is for someone out there to create a VS plugin for editing of sass/scss files. What I did find problematic was that when you have an error in your sass/scss code you only find it doing testing or inspecting of the generated CSS files. I haven't put it through all its paces, but so far so good.
https://github.com/xpaulbettsx/SassAndCoffee
我最初在此处回答了这个问题。
I originally answered this question here.