rollup-plugin-cloudport

Rollup plugin to convert NPM imports into CDN URL's

Usage no npm install needed!

<script type="module">
  import rollupPluginCloudport from 'https://cdn.skypack.dev/rollup-plugin-cloudport';
</script>

README

npm install size

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/hueman@v2.1.1-ElNqhC8YFxLlgRtjjL9o/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 to false). Whether to return relative exports (ex: ./supporting_file.js) as external
  • options.web_external: boolean (defaults to true). Whether to mark existing web imports (starting with "https://" or "http://") as external to be ignored.

License

MIT © Marshall Brandt