Install Bower components into two different directories?

被刻印的时光 ゝ 提交于 2019-12-03 02:20:44

问题


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

.
|-- 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?


回答1:


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.


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

(though not recommended)

  • grunt-bower-task
  • grunt-bower-organiser
  • grunt-bower



回答2:


There is a node package called bower-installer that provides a single command for managing alternate install paths.

run npm install -g bower-installer

Set up your 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-installer command.

This will install components/jquery-ui/themes/start/jquery-ui.css to ./src/css, etc




回答3:


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

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

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


来源:https://stackoverflow.com/questions/16041779/install-bower-components-into-two-different-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!