How to use NPM and Yarn in ASP.Net Core?

1

I am having difficulty using Yarn / NPM in ASP.Net Core.

I'm installing packages as follows: (Example installing JQuery)

Yarn: yarn add jquery NPM: npm install jquery

Everything happens normally, the problem is that the files go to the node_modules folder, whereas in ASP.Net Core it is "necessary" for the files to be in wwwroot .

I would love to use Bower , since it has set up the directories of the installations, however it is not working and is recommending the use of Yarn .

So how could I install packages to use in ASP.Net Core?

  

If possible, I would like the files to be installed in wwwroot/lib .

     

I searched, but I only found a few things in English, but I'm horrible in English and the browser translators do not seem to be that good, it's all confusing.

    
asked by anonymous 11.02.2018 / 04:27

1 answer

1

To do this, you can use the --modules-folder a>:

  

yarn install --modules-folder <caminho>

     

Specifies an alternate location for the node_modules directory, rather than the ./ node_modules pattern.

So in your case, you could install jquery using the following command:

$ yarn add jquery --modules-folder wwwroot/lib

Then your folder structure should look something like this:

pasta_raiz
├── package.json
├── wwwroot
│   └── lib
│       └── jquery
│           └── ...arquivos do jquery
└── yarn.lock

However, as you install more and more npm packages, it can be tiring to keep typing this flag with the path every time .

To "automate" the typing of this flag (and any other you need to use globally in your project), you can add a file . yarnrc in the root folder of your project with the following content:

--modules-folder wwwroot/lib

After that, simply use the commands yarn , yarn install or yarn add <pacote> and the modules will already be automatically saved in the ./wwwroot/lib folder of your project.

By the way, the Yarn documentation is already 100% translated into Brazilian Portuguese, now making it easier to understand and learn on the Yarn \ o /

    
09.08.2018 / 02:35