Specify different Yarn install paths for ‘devDependencies’ and ‘dependencies’
Asked Answered
R

1

10

I’m using Yarn to manage my dependencies for my project. I have developer dependencies (devDependencies) required for development and front-end dependencies (dependencies) that my project will require and use to run. I use Git to manage my version control.

Yarn by default seems to install all dependencies in the node_modules directory. This is fine for developer dependencies, but because I am using Git I typically ignore this directory. I would, however, like to commit my front-end dependencies and isolate them from developer dependencies.

I’m wondering if it’s possible to configure Yarn to install required dependencies in a separate directory from developer dependencies. For example:

  • devDependencies would be installed in /node_modules
  • dependencies would be installed in /vendor

Bower has similar functionality in the .bowerrc file but I can't find anything similar for Yarn. I considered using Bower alongside Yarn for my front-end dependencies but that seems to defeat the purpose of using Yarn.

Rack answered 25/3, 2017 at 3:32 Comment(3)
Have you made any progress here?Pechora
--cwd was recently added to Yarn to let you do this kind of thing. github.com/yarnpkg/yarn/pull/4174Exult
Why do you want to commit your front-end dependencies in the repo? I can think of good and bad reasons to do that. Is it because you want to serve static HTML pages directly from your repository in a gh-pages branch? Are you trying to make sure that the code of your dependencies never changes?Dierdredieresis
B
0

When you install a package to your repo you can install them by specifying -D at the end of it, for example yarn install some-package -D, this will add that package to the devDependencies tree in your package.json file, if You don't specify the -D that package will be added to the tree dependencies I believe that's how dependencies separation works

Bronwen answered 6/2, 2019 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.