2013-04-29 101 views
23

我正在試驗yeomanbower如何使用jowerUI與涼亭?

我曾嘗試使用下面的命令

yo webapp 

我想用jqueryui所以我一直在使用的涼亭安裝它創造了一個自耕農的webapp:

bower install jquery-ui --save 

也能正常工作,但jQuery的UI組件不包含帶有「全部」組件的JavaScript文件,它只包含很多JavaScript文件,每個組件都有一個。

我應該只包含我需要的JavaScript文件嗎?或者在使用jQuery UI之前我應該​​做些什麼?

感謝您的提示!

回答

3

如果您需要所有內容或僅用於實驗,我只需包含我需要的文件或使用文件夾中的默認自定義構建(我相信它具有所有組件)。

<script src="components/jqueryui/ui/jquery-ui.custom.js"></script> 

這時涼亭拉低整個回購,因爲(從他們的網站)「鮑爾只是一個包管理器」什麼都需要像串聯或加載模塊是由像鏈輪/ requirejs其他工具處理。

參考文獻:

主頁上使用包帶涼亭http://bower.io/

Dissusion約閨房,然後用jquery一起拉動整個回購 https://github.com/bower/bower/issues/45

+1

偉大的職位! bower的想法很棒,但它缺乏一種提供整個庫包的方式(即使項目沒有編譯成單個資源)。直到現在涼亭是一場噩夢:) – 2013-04-30 18:53:10

+0

jquery-ui.custom.js從1.10.2開始不再存在。我想你需要一些咕嚕的任務來建立它? – 2013-10-01 15:54:19

16

新增jquery-uibower.json(或component.jsondependencies

{ 
    …, 
    "dependencies": { 
    "jquery": "~1.9.1", 
    "jquery-ui": "~1.10.3", 
    ... 
    }, 
    … 
} 

安裝:

bower install 

然後,添加路徑jqueryuimain.js並要求其:

require.config({ 
    paths: { 
    jquery: '../components/jquery/jquery', 
    jqueryui: '../components/jquery-ui/ui/jquery-ui', 
    … 
    }, 
    shim: { 
    jqueryui: 'jquery', 
    … 
    }, 
    … 
}); 
require(['app', 'jquery', 'jqueryui', 'bootstrap'], function (app, $) { 
    'use strict'; 
    ... 
}); 

這對我的作品。

+9

OP沒有提到require.js – gotofritz 2015-02-21 23:57:35

-2

你可以使用requirejs.config的墊片屬性來實現自己的目標:

requirejs.config({ 
    shim: { 
     'jquery.ui.sortable': { 
      deps: ['jquery', 'jquery.ui.core', 'jquery.ui.widget', 'jquery.ui.mouse', 'jquery.ui.position'], 
      exports: '$' 
     } 
    } 
}); 

我們指定,即jquery.ui.sortable,需要在你的項目時,需要加載並執行deps下面列出的模塊第一,在被執行之前。

不幸的是,這仍然會產生競態條件......但是,這通常是一個將如何去這個(:

+0

我不認爲jquery.ui.position是jquery.ui.sortable的一個要求。 – 2013-10-16 15:55:15

+0

實際上,文檔沒有提到jquery.ui.position是必需的,但它當然是! – 2013-10-16 16:02:14

+1

OP沒有提到require.js – gotofritz 2015-02-21 23:56:26

5

在最新的jQuery UI的亭子組成,因爲我們說話(V 1.10。3),你可以做到以下幾點:

  1. 對於CSS主題,包括以下鏈接:

    <link rel="stylesheet" href="bower_components_path/jquery-ui/themes/base/jquery-ui.css">

  2. 爲了最有效的部件和運行jQueryUI的的小工具,包括以下腳本:

    <script src="bower_components_path/jquery-ui/ui/jquery-ui.js" ></script>

5

作爲參考,bower install jquery-ui --save會將jquery-ui.js依賴項添加到項目,但不添加樣式。對於我需要添加到bower.json文件的overrides部分,如下

{ 
    ..., 
    "dependencies": { 
    ..., 
    "jquery-ui": "^1.11.4" // already added with --save from bower install command 
    }, 
    ..., 
    "overrides": { 
    "jquery-ui": { 
     "main": [ 
     "themes/smoothness/jquery-ui.css", 
     "jquery-ui.js" 
     ] 
    } 
    } 
} 

參考文獻:

https://stackoverflow.com/a/27419553/4126114

https://github.com/taptapship/wiredep/issues/86

+0

使用wiredep的'overrides'也很好地工作,如果你想定製一個jquery-ui – plong0 2016-06-06 17:05:29