我正在制作一个使用来自twitter的bower的新项目。我创建了一个component.json
来维护我所有的依赖,比如jquery。然后我运行bower install
,将所有内容安装在名为components
的文件夹中。但我需要将组件安装在不同的文件夹中,例如public/components
。
我已尝试将components.json编辑为:
{
"name": "test",
"version": "1.0.0",
"directory": "public/",
"dependencies": {
"jquery": "*"
}
}
或:
{
"name": "test",
"version": "1.0.0",
"componentsDirectory": "public/",
"dependencies": {
"jquery": "*"
}
}
如https://github.com/twitter/bower/pull/94所示,但不起作用。
答案 0 :(得分:928)
使用内容在项目根目录(而不是您的主目录)中创建Bower configuration file .bowerrc
:
{
"directory" : "public/components"
}
再次运行bower install
。
答案 1 :(得分:76)
除了编辑.bowerrc
以设置默认安装路径外,您还可以为不同的文件类型设置自定义安装路径。
有一个名为bower-installer的节点包,它提供了一个用于管理备用安装路径的命令。
运行npm install -g bower-installer
设置你的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"
]
}
}
}
运行以下命令:bower-installer
这会将components/jquery-ui/themes/start/jquery-ui.css
安装到./src/css
等等
答案 2 :(得分:58)
我在Windows 10上遇到了同样的问题。这就解决了我的问题
bower_components
.bowerrc
文件
{"directory" : "public/bower_components"}
bower install
您现在应该在公用文件夹中看到bower_components文件夹
答案 3 :(得分:23)
如上所述,其他贡献者使用带有JSON的.bowerrc
文件
{ "directory": "some/path" }
是必要的 - 但是,在创建该文件时,您可能会在Windows上遇到问题。如果Windows为您提供了一条消息,要求您添加" 文件名",只需使用文本编辑器/ IDE,如Notepad ++。
将JSON添加到未命名的文件中,将其另存为 .bowerrc - 您还好![/ p>
可能是一个简单的假设,但我希望这可以为其他人带来不必要的麻烦:)
答案 4 :(得分:8)
尝试将components.json
文件放在应用程序的public
目录中,而不是根目录,然后重新运行bower install
...在您的应用主目录中尝试此操作:
cp components.json public
cd public
bower install
答案 5 :(得分:-3)
嗨,我是同样的问题,并解决这个问题。
windows user和vs cant'create .bowerrc文件。
在cmd中转到任何文件夹
安装任何包含.bowerrc文件的软件包,例如
bower install angular-local-storage
此插件包含.bowerrc文件。复制并转到您的项目并粘贴此文件。
在visual studio中 - 解决方案资源管理器 - 显示所有文件并包含项目 看到.bowerrc文件
我解决这个问题:)