🍣 A Rollup plugin which converts NodeJS imports into URL's for browser-side modules. Based on skypin
& unpkg-pin
.
Using npm:
npm install rollup-plugin-cloudport --save-dev
Suppose an input file containing the snippet below exists at src/index.js
, and attempts to load hueman
:
src/index.js
(input file)
// src/index.js
import { hueman } from 'hueman';
console.log(hueman(100,1.0,0.5));
Create a rollup.config.js
configuration file and import the plugin:
rollup.config.js
(input file)
import { skypin, unpkg } from 'rollup-plugin-cloudport';
export default [{
input: 'src/index.js',
output: {
file: 'dist/index.skypack.js',
format: 'esm'
},
// ...
plugins: [
skypin()
]
},{
input: 'src/index.js',
output: {
file: 'dist/index.unpkg.js',
format: 'esm'
},
// ...
plugins: [
unpkg()
]
}];
Then call rollup
either via the CLI or the API.
dist/index.js
(example output file)
import { hueman } from 'https://cdn.skypack.dev/pin/hueman@v2.1.1-ElNqhC8YFxLlgRtjjL9o/min/hueman.js';
console.log(hueman(100,1.0,0.5))
The options object can be used to customize the behavior of this plugin
options.shouldReplace()
:function(id) => boolean
(default to()=>true
). Customize which module ID's to replace using skypin.options.relative_external
:boolean
(defaults tofalse
). Whether to return relative exports (ex:./supporting_file.js
) asexternal
options.web_external
:boolean
(defaults totrue
). Whether to mark existing web imports (starting with "https://" or "http://") asexternal
to be ignored.
MIT © Marshall Brandt