Install node modules into your packages and automatically remove duplicate modules across 2GP packages using Salesforce DX.
This is an SFDX plugin. Install this plugin to your SFDX instance.
$ sfdx plugins:install sfdx-npm
This works by installing packages into the directory where package.json exists and where you run the command in the current working directory.
In the force-app directory, run the following to create a package.json file:
$ npm init
For second generation packaging, you will have a folder for each package. Each folder should contain their own package.json file. Follow the above instructions to create this file for each package.
When you install node modules, this plugin will identify other instances of node modules across the whole project and remove any duplicates.
To install a node module into your package, use the same parameters as npm install
. Change the prefix to sfdx npm:install
.
$ sfdx npm:install my-module --save
- CLI command for
$ sfdx npm:version:match [package]
- CLI command for
$ sfdx npm:module:clean