如何更改bower的默認組件文件夾?

本文翻譯自:How to change bower's default components folder?

I'm making a new project that uses bower from twitter. 我正在製作一個使用twitter的bower的新項目。 I created a component.json to maintain all my dependency like jquery. 我創建了一個component.json來維護我的所有依賴,比如jquery。 Then I run bower install that installs everything in a folder named components . 然後我運行bower install ,將所有內容安裝在名爲components的文件夾中。 But I need to install the components in a different folder, eg public/components . 但我需要將組件安裝在不同的文件夾中,例如public/components

I have tried editing my components.json into: 我已經嘗試將components.json編輯成:

{
  "name": "test",
  "version": "1.0.0",
  "directory": "public/",
  "dependencies": {
    "jquery": "*"
  }
}

or: 要麼:

{
  "name": "test",
  "version": "1.0.0",
  "componentsDirectory": "public/",
  "dependencies": {
    "jquery": "*"
  }
}

as shown in https://github.com/twitter/bower/pull/94 but it doesn't work. https://github.com/twitter/bower/pull/94所示,但它不起作用。


#1樓

參考:https://stackoom.com/question/x4o5/如何更改bower的默認組件文件夾


#2樓

Try putting the components.json file in the public directory of your application, rather than the root directory, then re-run bower install ...try this in your app home directory: 嘗試將components.json文件放在應用程序的public目錄中,而不是根目錄,然後重新運行bower install ...在您的app主目錄中嘗試此操作:

cp components.json public
cd public
bower install

#3樓

Create a Bower configuration file .bowerrc in the project root (as opposed to your home directory) with the content: 使用.bowerrc在項目根目錄(而不是主目錄)中創建Bower配置文件.bowerrc

{
  "directory" : "public/components"
}

Run bower install again. 再次運行bower install


#4樓

In addition to editing .bowerrc to setup your default install path, you can also setup custom install paths for different file types. 除了編輯.bowerrc以設置默認安裝路徑之外,您還可以爲不同的文件類型設置自定義安裝路徑。

There is a node package called bower-installer that provides a single command for managing alternate install paths. 有一個名爲bower-installer的節點包,它提供了一個用於管理備用安裝路徑的命令。

run npm install -g bower-installer 運行npm install -g bower-installer

Set up your bower.json 設置你的bower.json

{
  "name" : "test",
  "version": "0.1",
  "dependencies" : {
    "jquery-ui" : "latest"
  },
  "install" : {
    "path" : {
      "css": "src/css",
      "js": "src/js"
    },
    "sources" : {
      "jquery-ui" : [
        "components/jquery-ui/ui/jquery-ui.custom.js",
        "components/jquery-ui/themes/start/jquery-ui.css"
      ]
    }
  }
}

Run the following command: bower-installer 運行以下命令: bower-installer

This will install components/jquery-ui/themes/start/jquery-ui.css to ./src/css , etc 這將把components/jquery-ui/themes/start/jquery-ui.css./src/css


#5樓

Something worth mentioning... 值得一提的東西......

As noted above by other contributors, using a .bowerrc file with the JSON 如上面其他貢獻者所述,使用帶有JSON的.bowerrc文件

{ "directory": "some/path" }

is necessary -- HOWEVER, you may run into an issue on Windows while creating that file. 是必要的 - 但是,在創建該文件時,您可能會在Windows上遇到問題。 If Windows gives you a message imploring you to add a " file name ", simply use a text editor / IDE such as Notepad++. 如果Windows給您一條消息,要求您添加“ 文件名 ”,只需使用文本編輯器/ IDE,如Notepad ++。

Add the JSON to an unnamed file, save it as .bowerrc -- you're good to go! 將JSON添加到未命名的文件中,將其保存爲.bowerrc - 您很高興!

Probably an easy assumption, but I hope this save others the unnecessary headache :) 可能是一個簡單的假設,但我希望這可以節省其他不必要的頭痛:)


#6樓

Hi i am same problem and resolve this ways. 嗨,我是同樣的問題,並解決這個問題。

windows user and vs cant'create .bowerrc file. windows用戶和vs cant'create .bowerrc文件。

in cmd go any folder 在cmd中去任何文件夾

install any packages which is contains .bowerrc file forexample 安裝任何包含.bowerrc文件的包。例如

bower install angular-local-storage

this plugin contains .bowerrc file. 這個插件包含.bowerrc文件。 copy that and go to your project and paste this file. 複製並轉到您的項目並粘貼此文件。

and in visual studio - solution explorer - show all files and include project seen .bowerrc file 在visual studio中 - 解決方案資源管理器 - 顯示所有文件幷包含項目看到的.bowerrc文件

i resolve this ways :) 我解決這個問題:)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章