How to specify directory where Bower will place dependencies?

Asked

Viewed 395 times

0

I installed here in my machine the bower globally.

npm install -g bower

So when I use the remote bower install jquery, he installs it in the folder called bower_components.

Is there any way to make the bower install in a specific directory?

I want to install it in the directory public/js/ of my project.

  • you tried to create . bowerrc and set the directory?

  • Not yet, I’ll try now that you’ve spoken to me. Actually, this is the first time I’ve dealt with bower;

  • 1

    Take a look here http://bower.io/docs/config/, I believe solves your problem

3 answers

5


Use --config.cwd=[path], example:

bower install jquery --config.cwd=/home/brunorb/test
# /home/brunorb/test/bower_components/jquery/

Note that it still creates the folder bower_components within the specified right.

Another option is to use a file .bowerrc and set dir in key directory as shown here.

3

Create a file within the project root called .bowerrc with the following content:

{
  "directory": "/novo/local/das/dependencias"
}

1

I think the forms presented above are good, but if you have the need to manage your dependencies by specifying the folders, but each of them staying in a specific folder according to the type of script (css in one folder, and javascript in another), you can use the bower-installer.

To install it you simply wheel:

npm install -g bower-installer

After that, you should set on bower.json, the value "path" inside install, specifying the installation folders of each file extension.

Behold:

{
  "name" : "test",
  "version": "0.1",
  "dependencies" : {
    "jquery-ui" : "latest"
  },
  "install" : {
    "path" : {
      "css": "minha_pasta_personalizada/arquivos_css",
      "js": "minha_pasta_personalizada/arquivos_js"
    },
    "sources" : {
      "jquery-ui" : [
        "components/jquery-ui/ui/jquery-ui.custom.js",
        "components/jquery-ui/themes/start/jquery-ui.css"
      ]
    }
  }
}

The assignment "sources" defines which files you want to install in the specified directories.

Then, after this definition, just run the command:

 bower-installer

I’m using it and I think it’s very efficient.

  • Interesting, I didn’t know. Only this seems to bring a problem: if the internal path structure of the specified project changes in a new release you are obliged to fix your Switch.json to reflect it. Normally the change would already make you have to change the Imports in your HTML anyway, however so you have to change the HTML and the .bower.json, one more thing to keep. Still very useful in case for some reason you need specific paths.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.