This library adds simple, drop-in support for Sass/SCSS as well as CoffeeScript.
How to use:
First, add the desired package reference(s) via NuGet. You probably want SassAndCoffee.AspNet.
- Add a .coffee file to your project. For purposes of this example we'll use ~/Scripts/main.coffee
- By default the CoffeeScript compiler will wrap your scripts. If for some reason you want bare mode, request it:
Note: If a file exists named ~/Scripts/main.js, it will be served instead of ~/Scripts/main.coffee. SassAndCoffee always preferentially serves existing files on disk.
will serve the minified version of
- This of course works with CoffeeScript files (as described above), including bare support:
- Create a .combine file. We'll use ~/Scripts/home.combine for this example.
- Fill it with the absolute, relative, and App-relative paths of the scripts you want included:
# This line is a comment
# Include our minified CoffeeScript file with an absolute path
# Include another file in ~/Scripts
# Include a file in a subfolder of ~/Scripts
Note: For now, we recommend that you minify the included files, rather than the combined file. Uglify can choke on exceedingly large inputs.
Note: If a file exists named ~/Scripts/home.js, it will be served instead of ~/Scripts/home.combine. SassAndCoffee always preferentially serves existing files on disk.
- Add a .scss or .sass file to your project. We'll use ~/Content/site.scss for this example.
- Reference that file in your page as if it were compiled CSS:
- CSS combination can be achieved with
@import ""; directives
will serve the minified version of
Note: If a file exists named ~/Content/site.css, it will be served instead of ~/Scripts/site.scss. SassAndCoffee always preferentially serves existing files on disk.
What about performance?
SassAndCoffee offloads caching and compression to ASP.Net and IIS. To modify the default cache settings, alter the
SassAndCoffeeCacheSettings cache profile in web.config. To enable compression, install IIS's compression features.
SassAndCoffee watches your source files for changes and invalidates the cache when appropriate.
How does it work?
SassAndCoffee embeds the original compilers in the DLL (Sass 3.2.0 and CoffeeScript 1.1.3
as of this writing) and uses IronRuby and JScript respectively to execute the
compilers against your source.
SassAndCoffee will even use IE9's faster Chakra JScript engine if it's detected. Since JScript doesn't ship with Windows Server Core editions, it will not work on those systems.
Why is this better than [SOMEOTHERPROJECT]?
- No external processes are executed
- You don't have to install Ruby or node.js
- It's in NuGet so you don't have to fiddle with web.config
- Files are cached and are rebuilt as-needed.
If you run into bugs / have feature suggestions / have questions, please either send me an Email at [email protected], or file a Github bug.
Several folks helped me out with some of the integration details of this project
- if it weren't for them, I would still be stuck in the mud right now:
- David Padbury for helping me out with the CoffeeScript compiler
- Levi Broderick for giving me a few hints as to how to rig up the HttpModule
- Jimmy Schementi for telling me the proper way to redirect 'requires' to an embedded resource
- Thanks to Hampton Catlin and Jeremy Ashkenas for creating such awesome languages in the first place
- The folks on the #chromium IRC channel for helping me with a tricky V8 issue
- Steven Robbins for the ton of work put in to refactor the code to work with NancyFx and other non-ASP.NET frameworks
Adds Sass/SCSS, CoffeeScript, and UglifyJS support to ASP.Net projects. Works with WebForms and MVC
The SassAndCoffee Ruby compilers for Sass/SCSS. Great for integration into your own packages. Just include it as a dependency.
This legacy package is now an alias for SassAndCoffee.AspNet.