无点 - 不能与MVC捆绑单独的文件中引用变量少 [英] Dotless - Can't reference less variable in separate file with MVC Bundling

查看:232
本文介绍了无点 - 不能与MVC捆绑单独的文件中引用变量少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我没有创建一个重复的话题,但我一直在寻找了两天,无法找到解决这一点。

I hope I'm not creating a duplicate topic, but I've been searching for two days and can't find a solution to this.

我们是在开始的 MVC4 ,我们有以下的引导加载版本的新项目。我遇到的问题是,当我尝试引用在 bootstrap.less ,我的 global.less ,或当前文件以外的任何东西。我可以在当前文件的顶部创建一个变量,并使用它只是罚款,但如果我想使用的东西出一个单独的文件,我不得不 @import 它。这将是很好,如果我的整个应用程序的少了一个文件,但我不得不文件@import 4+到每一页/部分文件较小创建。

We are starting a new project in MVC4 and we have the less version of bootstrap loaded. The issue I'm running into is when I try to reference some classes or variables in the bootstrap.less, my global.less, or any thing outside the current file. I can create a variable in the top of the current file and use it just fine, but if I want to use something out of a separate file, I have to @import it. This would be fine if my entire app's less was in one file, but I'd have to @import 4+ files into each page/section less file I create.

我加了MVC4捆绑除了从 https://gist.github.com/2002958

I added the MVC4 bundling addition from https://gist.github.com/2002958

这个问题,因为我看到它,是每个文件进行评估并将其转换为独立的CSS。我试图简化流程和少包从所有的文件建立一个巨大的少字符串,然后将它们转换( Less.Parse(lessString)),但我m到处错误:

The issue, as I am seeing it, is that each file is evaluated and converted to css independently. I tried to simplify the process and build a massive less string from all of the files in the less bundle and then convert them (Less.Parse(lessString)), but I'm getting the error:

你正在导入的.LESS结尾的文件无法找到

"You are importing a file ending in .less that cannot be found"

因此,这里是我的终极问题:有没有办法简单地解析较少的字符串而不存在一个物理文件中引用?这将解决我的问题。

So here's my ultimate question: Is there a way to simply parse a less string without there being a physical file referenced? That would resolve my issue.

如果对于一些奇怪的原因是不可能的,有没有已经到位的组件或过程,我不知道,其实捆绑文件一起污染减量面前?

If that's not possible for some odd reason, is there a component or process already in place that I don't know about that actually bundles the files together before minifying them?

在这个问题上的任何光线,将不胜感激,因为我纺在圈子里试图让这个工作。

Any light on this subject would be appreciated as I am spinning in circles trying to get this to work.

这问题还张贴带点组中:结果
https://groups.google.com/forum/?fromgroups#!topic/dotless/j-8OP1dNjUY

This question was also posted in the Dotless group:
https://groups.google.com/forum/?fromgroups#!topic/dotless/j-8OP1dNjUY

推荐答案

这sollution为我工作:结果
I有两个包的NuGet:结果
带点结果
网​​络system.web.optimization

this sollution is working for me:
i have two nuget packages:
dotless
dotless adapter for system.web.optimization

无点适配器。配置我有这种线

in web.config i have this lines

<configuration>
    <configSections>
        <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
    </configSections>
    <system.web>
        <httpHandlers>
            <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
        </httpHandlers>
    </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
            <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
        </handlers>
    </system.webServer>
    <dotless minifyCss="true" cache="true" web="false" disableParameters="true" />
</configuration>

请注意,你应该用你的需求定义无点PARAMS。

note that you should define dotless params by your needs.

BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new LessBundle("~/bundles/styles/").Include(
        "~/Content/site.less"
    ));
    BundleTable.EnableOptimizations = True; //false if you want to debug css
}

和finaly Site.less

/*i have to redefine some bootstrap mixin and variables, so importing bootstrap and extending happings there*/
@import "bootstrap-extends.less";

/* all other needed less should be included here too
   for example:
   @import "admin.less";
   @import "controls.less";
   etc
*/

body{

}

site.less 引导-extends.less 在里面的内容的文件夹。< BR>
引导-扩展持有其在〜/内容/引导/ bootstrap.less

site.less and bootstrap-extends.less are inside Content folder.
bootstrap-extends holds all needed @import directives which are usualy listed in ~/Content/bootstrap/bootstrap.less

我希望这有助于

这篇关于无点 - 不能与MVC捆绑单独的文件中引用变量少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆