如何更改bower的默认组件文件夹?

本文详细介绍了如何修改Bower的默认组件安装目录。通过编辑.bowerrc文件,可以指定自定义的安装路径,如public/components。此外,还介绍了如何使用bower-installer管理不同类型的文件的安装路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值