Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to `yarn link` a dist folder?

Is there a way to do a yarn link to a dist or lib folder?

Here is my code structure:

/package-a
  - package.json
  - src/
    - ...
  - dist/
    - ...

If I do cd dist && yarn link and do yarn link package-a to another project, it links the package-a root folder and not the dist, making the import looks like this:

import fn from 'package-a/dist/fn';

instead of simply:

import fn from 'package-a/fn';

Any way to make this work aside from manually doing a symlink?

like image 883
edmandie Avatar asked Jul 15 '19 04:07

edmandie


People also ask

How do you use yarn links?

yarn link (in package you want to link) This command is run in the package folder you'd like to consume. For example if you are working on react and would like to use your local version to debug a problem in react-relay , simply run yarn link inside of the react project.

Is Yarn link the same as npm link?

yarn link is a command that helps during the development of npm packages. It links a local npm package to an existing project that uses yarn package manager. What this does is that it removes the need to create a new example project to test your npm package in development.

How use npm local link?

Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.

What does npm link do?

npm link is an npm command which, when used correctly, creates a link between projects to facilitate development in a local environment. This allows you to reference my-package locally (instead of the npm-hosted package) without modifying package. json in my-project.


1 Answers

yarn link will look for the folder where the package.json is in. So if you copy your package.json to your dist, it should work:

$ yarn unlink
$ cp package.json /dist
$ cd dist
$ yarn link
like image 100
MartijnvdB Avatar answered Oct 23 '22 02:10

MartijnvdB