admin管理员组

文章数量:1323508

Background

I have been using bower for handling dependencies, however now I would like to migrate to yarn. The main hurdle I am having is migrating from the below .bowerc file to .yarnrc.

.bowerrc

{
     "directory": "src/vendors"
}

The issue is I could make a .yarnrc file, like below that will put any dependency into src/vendors, but that includes devDependencies.

.yarnrc

--modules-folder src/vendors

Question

How do I only put dependencies into src/vendors and putdevDependencies in node_modules?

Background

I have been using bower for handling dependencies, however now I would like to migrate to yarn. The main hurdle I am having is migrating from the below .bowerc file to .yarnrc.

.bowerrc

{
     "directory": "src/vendors"
}

The issue is I could make a .yarnrc file, like below that will put any dependency into src/vendors, but that includes devDependencies.

.yarnrc

--modules-folder src/vendors

Question

How do I only put dependencies into src/vendors and putdevDependencies in node_modules?

Share edited Feb 18, 2018 at 16:11 tk421 5,9676 gold badges26 silver badges36 bronze badges asked Feb 16, 2018 at 0:40 Nicholas AdamouNicholas Adamou 74111 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

An alternative way to acplish the same thing as in the answer above (but without the .yarnrc files) is by adding two different scripts to package.json, something along these lines:

  "scripts": {
      "install-depends": "yarn install --production=true --modules-folder ./src/vendors",
      "install-devDepends": "yarn install --production=false"
   }

Then you just run them in that same order (if you do it the other way around, it will wipe out everything in the node_modules:

  1. yarn run install-depends
  2. yarn run install-devDepends

You could use --production option to tell yarn which dependencies you want to install; if set to true it will just install dependencies.

So in your src folder make a .yarnrc file with the following content:

--modules-folder vendors
--production true

and in your project dir, in .yarnrc file, set --production to false:

--production false

folder structure:

.
├── package.json
├── src
│   └── .yarnrc
└── .yarnrc

本文标签: javascriptHow do I only put dependencies into a specific folder for yarnStack Overflow