2012-11-15 20 views
9

我希望我不會創建一個重複的話題,但我一直在尋找兩天,找不到解決方案。無點 - 無法引用與MVC單獨文件中較少變量捆綁

我們開始在MVC4一個新的項目,我們有引導裝載的少版本。我遇到的問題是當我嘗試引用bootstrap.less,我的global.less中的某些類或變量或當前文件外的任何事物時。我可以在當前文件的頂部創建一個變量並使用它,但是如果我想從某個單獨的文件中使用某些內容,則必須使用@import它。如果我的整個應用程序少於一個文件,這將會很好,但是我必須將@ 4個以上的文件導入到每個頁面/部分中,而不是我創建的文件。

我說從https://gist.github.com/2002958

的MVC4捆綁另外的問題,因爲我看到它,是每個文件進行評估,分別轉換爲CSS。我試圖簡化流程,並在少束從所有文件建立一個巨大的較少的字符串,然後將它們轉換(Less.Parse(lessString)),但我得到的錯誤:

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

因此,這裏是我的終極問題:有沒有一種方法可以在沒有引用物理文件的情況下簡單解析一個較少的字符串?這將解決我的問題。

如果由於某種奇怪的原因導致這種情況不可行,是否有一個組件或流程已經到位,我不知道在將它們縮小之前實際上是否將這些文件捆綁在一起?

關於這個問題的任何燈光將不勝感激,因爲我正在旋轉圈試圖讓這個工作。

這個問題還張貼帶點組:
https://groups.google.com/forum/?fromgroups#!topic/dotless/j-8OP1dNjUY

+0

你有沒有發現一個解決方案,這一切都需要@import指令? –

+0

不幸的是,我從來沒有。我花了更多的時間比我認爲明智的,並繼續前進。對這個問題沒有解決辦法,我在最近的幾個項目中用得並不少。它似乎並不是我的需求的可行選擇。 – Difinity

回答

3

這sollution爲我工作:
我有兩個的NuGet包:
dotless
dotless adapter for system.web.optimization

web.config我有這個線

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

請注意,您應該定義根據您的需求提供無點的參數。

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.lessbootstrap-extends.less都在裏面的內容的文件夾。
bootstrap-extends保持其在~/Content/bootstrap/bootstrap.less

usualy上市我希望這有助於