【问题标题】:Specifying the location of .bowerrc when calling bower install调用 bower install 时指定 .bowerrc 的位置
【发布时间】:2015-05-06 02:08:57
【问题描述】:

我有一个包含子模块的父项目。该模块有自己的bower.json 指定模块依赖项和.bowerrc 指定这些应下载到哪个文件夹。这些依赖关系在模块 HTML 中链接。

父项目使用package.json管理Node依赖。

为了防止用户必须同时运行npm install(用于父依赖项)和cd modulebower installcd ../(用于模块依赖项),我在package.json 中添加了一个postinstall 脚本:

"scripts": {
    "postinstall" : "./node_modules/.bin/bower install ./module/ --config.directory=\"./module/public/bower_components\""
}

请注意,让 Bower 将模块的依赖项安装到 /module/public/bower_components 的唯一方法是在 postinstall 脚本中明确声明 directory

但是./module/.bowerrc 已经包含此信息,所以理想情况下我想“让”bower install 意识到这一点。这也将使package.json 更易于维护,module 更便携。

我还尝试将 Bower 依赖项和 postinstall 脚本转移到我模块的 package.json 中,使用父级 package.json 中的 postinstall 挂钩在模块目录中运行 npm install。但是这种方法以模块结束。依赖项正在下载到父级的 node_modules 文件夹中。

有没有更好的方法来解决这个问题?

【问题讨论】:

  • 为什么需要两个包管理器?也许你可以坚持使用 npm?
  • @GrimurD 如果它解决了这个问题,请你接受答案

标签: dependencies npm bower


【解决方案1】:

Bower 配置使用以下优先顺序来解析构建的配置。

来自 http://bower.io/docs/config/ 的 Bower 文档

  • CLI 参数通过 --config
  • 环境变量
  • 位于当前工作目录中的本地 .bowerrc
  • 目录树上方的所有 .bowerrc 文件
  • .bowerrc 文件位于用户的主文件夹 (~)
  • .bowerrc 文件位于全局文件夹 (/) 中

在您的情况下,您可以将 .bowerrc 文件放在与 package.json 相同的文件夹中,但使用前缀 module/public 配置所有属性以使您的设置正常工作。

我确实喜欢你从 package.json 中的一个位置管理所有依赖项的想法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 2014-07-26
    • 1970-01-01
    • 2015-04-27
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多