简体   繁体   English

使Squish表现像AssMan

[英]Make SquishIt behave like AssMan

I'm working on an MVC4 site, and I would like to use some resource management software to consolidate & minify JS & CSS (+ less & coffeescript), 我正在MVC4网站上工作,我想使用一些资源管理软件来合并和最小化JS和CSS(+ less&coffeescript),

SquishIt has all the plugins I want, they're already configured. SquishIt具有我想要的所有插件,它们已经配置好了。 All the examples show a very simple idea behind SquishIt, which never includes any asset management. 所有示例都显示了SquishIt背后的一个非常简单的想法,该想法从不包含任何资产管理。 It looks like (and the JavaScript model is almost identical): 看起来像(和JavaScript模型几乎相同):

<html>
  <head>
    @Html.BundleCss()
            .Add("~/Content/first_file.css")
            .Add("~/Content/second_file.css")
            .Add("~/Content/third_file.css")
            .Render()
  </head>

What I'm wanting to do is more like this: 我想做的更像是这样:

_Layout.cshtml:
<html>
  <head>
    @Html.BundleCss().Render()
  </head>
  ....

App_Start():
  Bundle.Css().Add("~/Content/bootstrap.css").Add("~/Content/jquery-ui.css");

_PartialView.cshtml:
  @Html.BundleCss().AddString("a:active { color: red }")

The idea behind this is that I would build up the CSS/JS I need as the views recursively render and then the minifier builds, minifies, and caches at the end. 其背后的想法是,当视图递归呈现时,我将构建所需的CSS / JS,然后minifier最终构建,最小化和缓存。 AssMan ( http://assman.codeplex.com/ ) does this, but seems less supported and requires more work to get the required minifiers and language support I want. AssMan( http://assman.codeplex.com/ )做到了这一点,但似乎不那么受支持,并且需要更多的工作来获得我想要的必需的简化程序和语言支持。

Ideas, suggestions? 有想法,建议吗?

Cassette seems to do this natively. 盒式磁带似乎是本地执行的。 It's not as clean of a syntax as I'd like (I'd prefer being able to reference arbitrary scripts and CSS from pages without having to bundle them) but it does work. 它不像我想要的那样干净(我更希望能够从页面引用任意脚本和CSS而不必捆绑它们),但是它确实可以工作。

If I'm following your question correctly, I think this issue is about as close as you're going to get (started from this SO thread ). 如果我正确地遵循了您的问题,我认为这个问题与您将要解决的问题差不多(从此SO线程开始)。 I don't really follow though, what bundle should the .AddString call in your example be added to? 不过,我并不是很了解,您的示例中的.AddString调用应添加到哪个捆绑包中? It looks to me like you are going to end up with a single combined file per view, which is about as bad as you can get from an optimization perspective. 在我看来,您最终将在每个视图中得到一个合并的文件,从优化的角度来看,这几乎是一样糟糕。

If you read the discussion on that issue and check out the linked commits maybe it will give you some ideas about how to get the functionality you're after (it might actually be the AutoBundler stuff we've implemented, that is available in prerelease now, and will be getting a soft release in the very near future). 如果您阅读了有关该问题的讨论并查看了链接的提交,也许它将为您提供有关如何获得所需功能的一些想法(实际上可能是我们已经实现的AutoBundler内容,现在可以在预发行版中找到) ,并且将在不久的将来进行软发布)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM