Browserify tranform to use require() for loading resources from jsDelivr.
require('jquery.cdn');
// Transforms to:
require('.cdncache/jquery/main.js');
- Recognizes if the required file name contains a .cdn extension.
- Check if the required library is already downloaded.
- Transforms the required file name to the relative path of the downloaded library.
- If isn't downloaded, checks if the required library exists on jsdelivr.com.
- Downloads the latest mainfile of the library into the .cdncache directory via this url:
https://cdn.jsdelivr.net/<library>/latest/mainfile
- Transforms the required file name to the relative path of the downloaded library.
npm install browserify-cdnjs
// gulpfile.js
var cdnjs = require('browserify-cdnjs');
browserify('index.js')
.transform(cdnjs)
.bundle();