2014-01-09 21 views
0

在開發模式下有沒有辦法忽略css規則,但是之後在編譯之後顯示該規則。減:在開發模式下忽略規則

例如在文件foo.less

.foo { 
    background: green; //ignore this file in development mode 
} 

,但由於您使用的生產和開發不同的環境對應的CSS文件將使用此規則

+0

不完全確定你的意思。有沒有辦法在沒有編譯的情況下使用更少的方法?也許'開發模式'是你的IDE特有的? –

+0

嗯,我正在使用grunt將所有較少的文件構建到一個css文件中。我的意思是開發模式是我使用less.js應用css規則。然後生產模式使用編譯後的css文件。 – Bob

回答

0

我最終只是在減檔加一個變量,然後重寫該變量在開發模式,而less.js:

less.modifyVars({ foo: "auto" }) 
在較少文件

則:

@foo: green 
.foo { 
    background: @foo 
} 
2

反正它會更容易簡單地包裹你 -

// --------- 
// main.less - this is your main less built with grunt 

// ... 
// all your code here 
// ... 

@debug: false; 

.foo { 
    & when not(@debug) {background: green} // ignore this file in development mode 
} 

// ---------- 
// debug.less - this is the "development" wrapper to use with less.js in a browser 

@import "main.less" 
@debug: true; 

:與 「調試」 唯一模式,例如,另一個較小的文件更少的代碼

& when快捷方式需要較少的1.5.1,早期版本的使用:

.-() when not(@debug) { 
    background: green; 
} .-; 

代替。