rollup-plugin-cloudport
v0.0.2
Published
Rollup plugin to convert NPM imports into CDN URL's
Downloads
19
Maintainers
Readme
rollup-plugin-cloudport
🍣 A Rollup plugin which converts NodeJS imports into URL's for browser-side modules. Based on skypin
& unpkg-pin
.
Install
Using npm:
npm install rollup-plugin-cloudport --save-dev
Usage
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/[email protected]/min/hueman.js';
console.log(hueman(100,1.0,0.5))
Options
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.
License
MIT © Marshall Brandt