javascript 将 Bower 组件安装到两个不同的目录中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16041779/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:01:41  来源:igfitidea点击:

Install Bower components into two different directories?

javascriptcomponentssassorganizationbower

提问by Robb Schiller

When using CSS and JS components, is it possible, or even, does it make sense to install them to different directories?

使用 CSS 和 JS 组件时,是否可以,甚至将它们安装到不同的目录是否有意义?

.
|-- app
    |-- scripts
        |-- components           # js components go here
            |-- backbone-amd
            |-- etc
    |-- styles
        |-- modules
        |-- partials
        |-- components           # sass components go here
            |-- normalize.scss
            |-- etc

What's the most efficient way to structure a project organized as such? Is there a good Grunt task to accomplish the goal of integrating bower installed sass components for a development environment?

构建这样组织的项目的最有效方法是什么?是否有一个很好的 Grunt 任务来完成为开发环境集成 bower 安装的 sass 组件的目标?

采纳答案by Sindre Sorhus

Bower needs to keep track of every component you install. That would be very hard if they were split up in multiple locations. For Sass development, just put the components folder in the Sass search path.

Bower 需要跟踪您安装的每个组件。如果将它们拆分到多个位置,那将非常困难。对于 Sass 开发,只需将 components 文件夹放在 Sass 搜索路径中即可。



There are grunt tasksthat can assist you in splitting it up if you insist on doing that:

如果您坚持这样做,有一些繁重的任务可以帮助您将其拆分:

(though not recommended)

(虽然不推荐)

回答by lfender6445

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"
      ]
    }
  }
}

Then run bower-installercommand.

然后运行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 Michael Vashchinsky

Maybe You can have .bowerrcfiles in different directories, where you can config "directory"key to point to bower components directory.

也许您可以.bowerrc在不同的目录中拥有文件,您可以在其中配置"directory"键以指向 bower 组件目录。

But you will need to cdto correct directory before bower install whatever:

但是您需要在cd之前更正目录bower install whatever

app/
  scripts/
    .bowerrc
  styles/
    .bowerrc
tests/
  .bowerrc