pika-plugin-build-legacy-browser

A @pika/pack plugin: Adds an IIFE bundled distribution to your package for supporting legacy browsers. Built & optimized to run in all browsers.

Usage no npm install needed!

<script type="module">
  import pikaPluginBuildLegacyBrowser from 'https://cdn.skypack.dev/pika-plugin-build-legacy-browser';
</script>

README

pika-plugin-build-legacy-browser

A @pika/pack build plugin. Adds an IIFE bundled distribution to your package for supporting legacy browsers. Built & optimized to run in all browsers. Useful for hosting on a CDN like UNPKG and/or when package dependencies aren't written to run natively on the web.

Install

# npm:
npm install pika-plugin-build-legacy-browser --save-dev
# yarn:
yarn add pika-plugin-build-legacy-browser --dev

Usage

{
  "name": "example-package-json",
  "version": "1.0.0",
  "@pika/pack": {
    "pipeline": [
      ["@pika/plugin-standard-pkg"],
      ["pika-plugin-build-legacy-browser", { /* options (optional) */ }]
    ]
  }
}

Options

  • "sourcemap" (Default: "true"): Adds a source map for this build.
  • "namedExports" (Default: undefined): Ecplicitly specify unresolvable named exports (See rollup-plugin-commonjs for more information).
  • "minify" (Default: true): Specify if bundle should be minifed using terser or not. Can also be terser options object to further tweak minification.
  • "entrypoint" (Default: "browser"): Customize the package.json manifest entrypoint set by this plugin. Accepts either a string, an array of strings, or null to disable entrypoint. Changing this is not recommended for most usage.
    • {"entrypoint": "browser"} will create an "browser" entrypoint that points to "dist-browser/index.min.js". This is supported by both unpkg and jsdelivr.
    • {"entrypoint": ["unpkg", "jsdelivr"]} will create both "unpkg" & "jsdelivr" "dist-browser/index.min.js" entrypoints.

Result

  1. Adds a web bundled distribution to your built package: dist-browser/index.min.js
  2. Transpiled to run on all browsers
  3. All dependencies inlined into this file.
  4. Minified using terser (Can optionally be skipped)
  5. (if specified) Adds the file to your specified "entrypoint".