Jason Kim
Jason Kim

Reputation: 19051

yarn - install modules in a specific directory

When I do $ yarn install, I see that ./node_modules directory gets created and modules are installed in that directory.

I also get that --modules-folder ./directory_location exists, to install in a specific directory one time.

Is there an option to always use a specific directory to install in package.json configuration?

Upvotes: 20

Views: 37068

Answers (3)

codepig
codepig

Reputation: 541

"scripts": {
    "postinstall": "cd subdirectory && yarn install", //exec after yarn install automatically
}

Upvotes: 1

twk
twk

Reputation: 1841

Create a .yarnrc file in your root project folder, along side, package.json.

Inside of .yarnrc, add the following:

# install modules here
--modules-folder apps/my_cool_application/static/

# Note: target directory goes after `--modules-folder` {{target dir}}

In this example, running yarn install will install all modules into ./apps/my_cool_application/static, so for example,

Bootstrap, after being installed would live in: ./apps/my_cool_application/static/bootstrap

Note: If your node_modules folder currently exists, you can delete it after creating .yarnrc and run yarn install for all your packages to be downloaded again into your targeted directory.

This site had a helpful walk through, and offers some additional information.

Upvotes: 8

Jason Kim
Jason Kim

Reputation: 19051

I am now using scripts to do this.

And I can run yarn run newinstall

In package.json

{
    ...
    "scripts": {
        "newinstall": "yarn install --modules-folder ./directory_location"
    }
    ...
}

Upvotes: 21

Related Questions