Varbase Libraries
Drupal Libraries Management
The NPM/Yarn Method
List of needed libraries for Varbase Projects which uses packages with NPM/YARN.
NPM/Yarn dynamic way of managing packages as libraries.
By adding all needed libraries in "dependencies" and "drupal-libraries" in the package.json file in projects.
Available Drupal Libraries Sync Commands
yarn drupal-libraries-sync
Sync libraries using Yarn NPM/Yarn.
npm run drupal-libraries-sync
Sync libraries using.
composer drupal-libraries-sync
Sync libraries via Composer (uses Yarn by default).
composer drupal-libraries-yarn-sync
Sync libraries via Composer using Yarn.
composer drupal-libraries-npm-sync
Sync libraries via Composer using NPM.
Adding New Libraries
Search for packages in https://www.npmjs.com
1. Add to package.json Dependencies
{
"dependencies": {
"npm-package-to-start-using": "^1.0.0"
}
}2. Configure Library Mapping
Add the library mapping to the drupal-libraries section:
3. Install and Sync
Example:
1- Let us imagine that we need the chart.js npm library in a project, to be used with the Chart module along with the C3 and D3 npm libraries. (Search for packages in https://www.npmjs.com)
2- Add the following in
"dependencies"3- Add the following in
drupal-libraries.libraries4- Run the following script to sync selected drupal libraries from node_module to docroot/libraries.
5- Check that you do have the new libraries in your
docroot/librariesfolder.6- Notice that the package
chart.jswas copied fromnode_modulesand when thechartjsname, as the Chart module was developed to locate thechartjsfolder in libraries.
For more examples have a look at "dependencies" and "drupal-libraries" in the package.json
Removing No Longer Needed Libraries
1. Remove from the package.json file.
Remove the library from both dependencies and drupal-libraries.libraries sections.
2. Clean Up Files
Troubleshooting
Libraries Not Appearing
Verify
package.jsonsyntax is validCheck that the library mapping in
drupal-libraries.librariesis correctEnsure the sync script exists at
./docroot/profiles/contrib/varbase/scripts/drupal-libraries-sync.jsRun sync command manually:
yarn drupal-libraries-sync
Permission Issues
Switch from Asset Packagist to NPM/Yarn
Migrating Existing Projects to NPM/YARN with drupal-libraries-syncThe Composer Method (Deprecated)Last updated