node.js 如何更改凉亭的默认组件文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14079833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change bower's default components folder?
提问by Adam Ramadhan
I'm making a new project that uses bower from twitter. I created a component.jsonto maintain all my dependency like jquery. Then I run bower installthat installs everything in a folder named components. But I need to install the components in a different folder, e.g. public/components.
我正在制作一个使用来自 twitter 的 bower 的新项目。我创建了一个component.json来维护我所有的依赖项,比如 jquery。然后我运行bower install将所有内容安装在名为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/94but it doesn't work.
如https://github.com/twitter/bower/pull/94所示,但它不起作用。
回答by Adam Ramadhan
Create a Bower configuration file .bowerrcin the project root (as opposed to your home directory) with the content:
在项目根目录(而不是您的主目录)中创建一个Bower 配置文件.bowerrc,内容如下:
{
"directory" : "public/components"
}
Run bower installagain.
再跑bower install。
回答by lfender6445
In addition to editing .bowerrcto setup your default install path, you can also setup custom install paths for different file types.
除了编辑.bowerrc以设置默认安装路径之外,您还可以为不同的文件类型设置自定义安装路径。
There is a node package called bower-installerthat 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.cssto ./src/css, etc
这将安装components/jquery-ui/themes/start/jquery-ui.css到./src/css等
回答by Tim Anishere
I had the same issue on my windows 10. This is what fixed my problem
我在 Windows 10 上遇到了同样的问题。这就是解决我的问题的原因
- Delete
bower_componentsin your root folder - Create a
.bowerrcfile in the root - In the file write this code
{"directory" : "public/bower_components"} - Run a
bower install
bower_components在你的根文件夹中删除.bowerrc在根目录创建一个文件- 在文件中写下这段代码
{"directory" : "public/bower_components"} - 运行一个
bower install
You should see bower_components folder in your public folder now
您现在应该在公共文件夹中看到 bower_components 文件夹
回答by Cody
Something worth mentioning...
值得一提的事...
As noted above by other contributors, using a .bowerrcfile with the JSON
如上所述,其他贡献者使用.bowerrc带有 JSON的文件
{ "directory": "some/path" }
{ "directory": "some/path" }
is necessary -- HOWEVER, you may run into an issue on Windows while creating that file. If Windows gives you a message imploring you to add a "file name", simply use a text editor / IDE such as Notepad++.
是必要的——但是,您在创建该文件时可能会在 Windows 上遇到问题。如果 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 :)
可能是一个简单的假设,但我希望这可以避免其他人不必要的头痛:)
回答by hagope
Try putting the components.jsonfile in the publicdirectory 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...在您的应用程序主目录中试试这个:
cp components.json public
cd public
bower install
回答by Abdullah SARGIN
Hi i am same problem and resolve this ways.
嗨,我是同样的问题,并以这种方式解决。
windows user and vs cant'create .bowerrc file.
windows 用户和 vs 无法创建 .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. copy that and go to your project and paste this file.
这个插件包含 .bowerrc 文件。复制它并转到您的项目并粘贴此文件。
and in visual studio - solution explorer - show all files and include project seen .bowerrc file
并在 Visual Studio - 解决方案资源管理器中 - 显示所有文件并包含项目看到的 .bowerrc 文件
i resolve this ways :)
我以这种方式解决:)

