2014-01-23 40 views
6

我在讀http://sailsjs.org/#!documentation/assets,但我不知道如何使用.less文件。如何在sails.js中使用.less文件?

我把vairables.less和bootswatch.less無論是在資產/連接/風格/

我預計咕嚕會編譯這兩個文件,但它沒有,和我在瀏覽器控制檯,而不是錯誤:

GET http://localhost:5000/linker/styles/bootstrap-responsive.css 404 (Not Found) (index):14 
GET http://localhost:5000/linker/styles/bootstrap.css 404 (Not Found) (index):15 
GET http://localhost:5000/linker/js/jquery.js 404 (Not Found) (index):29 
GET http://localhost:5000/linker/js/socket.io.js 404 (Not Found) (index):30 
GET http://localhost:5000/linker/js/sails.io.js 404 (Not Found) (index):31 
GET http://localhost:5000/linker/js/app.js 404 (Not Found) (index):32 
GET http://localhost:5000/linker/js/bootstrap.js 404 (Not Found) 

如果我刪除了兩個.less文件,它可以正常工作。 我在這裏錯過了什麼?

+1

看起來是沒有得到填充你的.tmp目錄。 Grunt是否會拋出任何錯誤?用--verbose提起帆以檢查。 – sgress454

+1

這是因爲在較少的文件中有一些錯誤。謝謝。詳細信息:Grunt :: >> NameError:.box-shadow在asset/linker/styles/bootswatch.less中未定義:21:2 >> 20 border-top-color:@ dropdown-divider-bg; >> 21 .box-shadow(none); >> 22} – Vadorequest

+2

我真的認爲這種錯誤不應該顯示爲冗長。很難調試! – Vadorequest

回答

3

我已經決定不使用啓動默認進口商。主要是因爲我發現它很糟糕,太多基於配置而非慣例。所以我已經根據約定通過配置創建了我自己的動態資產加載器。

基本上,在我的情況下,沒有更多的事情要做,資產將根據所使用的控制器,控制器動作,主題和佈局進行應用。它仍然使用LESS。

這是基於帆0.10.5一個簡單的項目: https://github.com/Vadorequest/sails-dynamic-assets

3

如果您正在使用最新版本的Sails.js的然後把資產規模/樣式目錄中的文件.LESS並將其包含在importer.less文件象下面這樣:

/** 
* importer.less 
* 
* By default, new Sails projects are configured to compile this file 
* from LESS to CSS. Unlike CSS files, LESS files are not compiled and 
* included automatically unless they are imported below. 
* 
* The LESS files imported below are compiled and included in the order 
* they are listed. Mixins, variables, etc. should be imported first 
* so that they can be accessed by subsequent LESS stylesheets. 
* 
* (Just like the rest of the asset pipeline bundled in Sails, you can 
* always omit, customize, or replace this behavior with SASS, SCSS, 
* or any other Grunt tasks you like.) 
*/ 



// For example: 
// 
// @import 'variables/colors.less'; 
// @import 'mixins/foo.less'; 
// @import 'mixins/bar.less'; 
// @import 'mixins/baz.less'; 
// 
// @import 'styleguide.less'; 
// @import 'pages/login.less'; 
// @import 'pages/signup.less'; 
// 
// etc. 
@import 'custom.less'; 
+3

感謝您的回答,我已經解決了很久以前,忘記了這個問題;)我不這樣做,因爲你必須指定每個無聊的文件。因爲我把我的代碼分成很多文件,所以需要時間。我所做的是我有一個* File Watcher *,每當我更改其中一個時,它就編譯我所有的'less'文件。然後咕嚕任務只是在開始時導入所有的'css'文件並在任何改變時刷新'.tmp'。它以這種方式正常工作,並且是動態的。 – Vadorequest

+0

我是新的node.js和sails.js。我非常有興趣瞭解您詳細瞭解的過程。您能否將此作爲您自己問題的答案發布? – chanchal1987

+2

好的!我也會嘗試設置一個小例子項目,所以它很容易理解。 – Vadorequest

相關問題