2014-01-05 38 views
45

我正在下載帶有涼亭的角度引導和bootstrap。 Bootstrap對jquery有依賴性,它在進程中安裝。但我不需要它在我的項目中,因爲我只使用引導程序的CSS。永久忽略與涼亭的依賴關係

所以我試圖永久刪除jQuery的依賴與

bower uninstall jquery --save 

它卸載jQuery的,但下一次我讓bower update,它再次下載。

有沒有辦法告訴鮑爾永久跳過依賴?

編輯:我希望有這樣的事情:

"resolutions": { 
    "jquery": "no, thanks" 
} 

回答

65

Pull request #1394增加官方支持爲此功能,並存在於涼亭版本1.6.3和更高版本。用bower -v檢查您的版本,並運行npm install -g bower進行升級。請參閱.bowerrc official specification document。如果這不適合你,請file an issue with bower,因爲它是一個錯誤。

我們在使用這樣我們.bowerrc如下列:

{ 
    "ignoredDependencies": [ 
    "bootstrap", 
    "bootstrap-sass", 
    "bootstrap-sass-official" 
    ] 
} 
+0

這仍然沒有合併? – Vic

+0

我可以證實我也得到這個PR的問題,所以它甚至不是完整的解決方案 - https://github.com/bower/bower/pull/1394#issuecomment-73864285 – streetlogics

+1

它不適用於涼亭1.7.0,來自@pierrefevrier的答案幫助我http://stackoverflow.com/a/32016391/ 232342 –

5

它添加到您的.gitignore如果你提交你的依賴。否則,因爲它沒有區別,所以留下它。你應該只使用你需要的而忽略其餘的。

+1

什麼我沒有提交依賴關係。所以我知道這是不可能跳過它,我會離開它。謝謝 –

+1

我不認爲這是要走的路......收縮包裹是非常必要的 – stevemao

+1

當你捆綁你的腳本但是想要拋棄從CDN加載的庫時,它確實有所幫助。我已經通過鮑爾安裝了一個角度庫,我捆綁了我的js應用程序,但我通過谷歌CDN服務角本身。如果忽略這個dep,使捆綁方式更容易。 – jminuscula

25

我們有類似的情況,我們的Backbone依賴於Underscore的bower.json,但我們使用的是Lo-Dash代替,所以Bower在每次安裝時都不必要地下拉Underscore。我們對第三方許可證合規性進行了自動檢查,因此我們不需要任何我們沒有實際使用的內容。

我意識到這並不完全是他們的意思,但鮑爾的install-hooks可以用來清理不必要的代價後安裝(至少直到鮑爾得到你暗示的那種「不,謝謝」的決議)。在你.bowerrc

{ 
    "directory": "app/bower_components", 
    "scripts": { 
     "postinstall": "rm -rf app/bower_components/underscore" 
    } 
} 

這是一個黑客攻擊的一位,但工程。

+3

有趣的解決方案!但它不能解決使用wiredep這樣的工具而沒有配置它的問題:( – stevemao

1

以上的答案是正確的,但額外的解決方案是使用wiredep在這個答案解釋:

grunt-bower-install: exclude certain components

安裝grunt-wiredep後,你可以添加類似於你的Grunt.js來排除jquery被注入的內容:

// Automatically inject Bower components into the app 
wiredep: { 
    options: {}, 
    app: { 
    src: ['<%= my.app %>/index.html'], 
    exclude: ['bower_components/jquery'] 
    } 
}, 

Bower仍然會不幸地下載jquery,但至少你可以告訴它不要包含在HTML src中。

1

免責聲明:這不能解決您的特定問題,但它對我有幫助,所以也許它會幫助其他人。

我正在使用grunt-bower-task將文件拉入lib目錄。我想排除「角」,只包括「angular.js」。我的一個依賴關係是「角度」拉動。在我bower.json我現在有:

{ 
    "name": "myapp", 
    "version": "0.0.1", 
    "dependencies": { 
    "angular.js": "1.3.15", 
    "angular-bootstrap": "0.13.0", 
    "angular-cookies": "1.3.15", 
    "angular-storage": "0.5.0", 
    "angular-ui-router": "0.2.15", 
    "mjolnic-bootstrap-colorpicker": "2.1" 
    }, 
    "exportsOverride": { 
    "angular": { 
     "dump": "*.xxx" 
    }, 
    "angular.js": { 
     "js": [ "*.js", "*.js.map" ], 
     "css": "*.css" 
    } 
    }, 
    "resolutions": { 
    "angular": "1.3.15" 
    } 
} 

在我gruntfile.js我:

bower: { 
    install: { 
     options: { 
      targetDir: './lib', 
      layout: 'byType', 
      install: true, 
      cleanTargetDir: true, 
      cleanBowerDir: false 
     } 
    } 
}, 

這被複制到目標停止「角」的文件。

13

有些事情,你還可以做你的bower.json文件:

{ 
    "dependencies": { 
    ... 
    "bootstrap": "^3.2.0" 
    } 
    "overrides": { 
    "bootstrap": { 
     "dependencies": [] 
    } 
    } 
} 

這意味着:刪除所有自舉的依賴,這是你想要的,因爲jQuery是唯一一個(你可以用bower info bootstrap檢查)

+0

這實際上並不支持Bower,是嗎? – JKillian

+0

是的,這是我的代碼片段。 – pierrefevrier

+0

據我所知,這不是規範的一部分:https://github.com/bower/bower.json-spec/pull/27 – JKillian