3

Here is my scenario:

  • I have 7 different webparts
  • In order to have more control over the projects, I have split them in different projects
  • All of the projects were created using the Yeoman installer

All was fine until I started to add them to the pipeline. Then I realize that I need to make npm install for every project. This is causing delay in my build pipeline as well as disk space.

My question is: How can different webpart solutions share single node_modules folder?

Regards,

Dimitar

2
  • 1
    As per my knowledge you cannot share node modules folder in multiple solutions. Commented Jan 7, 2021 at 11:59
  • 1
    yeah...i was afraid so...thanks for the info
    – JohnRambo
    Commented Jan 7, 2021 at 15:09

3 Answers 3

3

Instead of creating a different projects for the webparts, please create all the webparts in a single SPFx solution. These webparts will share the common node_modules folder of the SPFx solution.

Reference link: https://www.c-sharpcorner.com/article/add-multiple-webparts-to-single-spfx-solution-using-yeoman/

1
  • Good suggestion but unfortunately the projects have to be separated since we dont want to ship all of our webparts per client.
    – JohnRambo
    Commented Jan 7, 2021 at 10:51
2

This is standard behaviour and the best approach for various reasons.

Each project (which can include 1 or more webparts) needs to have a node_modules folder. This ensures that who ever builds your project will have the same exact result. Global modules are not declared at the project level, which could open the possibility for issues related to module versions.Trust me, issues with versions of global modules can be really hard to deal with.

0

You can use pnpm command to install. It will reduce size of node_modules folder. Here are some resources which will help you :

  1. https://www.youtube.com/watch?v=gCwV58BVWMU
  2. https://www.voitanos.io/blog/npm-yarn-pnpm-which-package-manager-should-you-use-for-sharepoint-framework-projects/
  3. https://www.m365-dev.com/2018/10/31/using-pnpm-with-spfx/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.