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

时间:2012-12-29 07:55:04

标签: node.js bower

我正在制作一个使用来自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所示,但不起作用。

6 个答案:

答案 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上遇到了同样的问题。这就解决了我的问题

  1. 删除根文件夹中的bower_components
  2. 在根
  3. 中创建.bowerrc文件
  4. 在文件中编写此代码{"directory" : "public/bower_components"}
  5. 运行bower install
  6. 您现在应该在公用文件夹中看到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文件

我解决这个问题:)

相关问题