本文翻译自: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 :) 我解决这个问题:)