All Projects → eight04 → rollup-plugin-external-globals

eight04 / rollup-plugin-external-globals

Licence: MIT license
Transform external imports into global variables like output.globals.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rollup-plugin-external-globals

rollup-plugin-collect-sass
Collect Sass, then compile
Stars: ✭ 17 (-70.18%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-purs
Bundles PureScript modules with Rollup
Stars: ✭ 71 (+24.56%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-markdown
import JavaScript from Markdown code blocks
Stars: ✭ 16 (-71.93%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-lit-css
Moved to https://github.com/bennypowers/lit-css
Stars: ✭ 35 (-38.6%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-userscript-metablock
Transform json file to userscript metablock and append on.
Stars: ✭ 26 (-54.39%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-inject-process-env
Inject environment variables in process.env with Rollup
Stars: ✭ 48 (-15.79%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-tagged-template
Use plain HTML files as tagged templates.
Stars: ✭ 24 (-57.89%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-sizes
Rollup plugin to display bundle contents & size information
Stars: ✭ 77 (+35.09%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-closure-compiler-js
Rollup plugin for optimizing JavaScript with google-closure-compiler-js.
Stars: ✭ 31 (-45.61%)
Mutual labels:  rollup, rollup-plugin
postcss-font-grabber
A postcss plugin, it grabs remote font files and update your CSS, just like that.
Stars: ✭ 26 (-54.39%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
Stars: ✭ 52 (-8.77%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-html
Import HTML files as strings in rollup build
Stars: ✭ 36 (-36.84%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-generate-html-template
Rollup plugin for automatically injecting a script tag with the final bundle into an html file.
Stars: ✭ 58 (+1.75%)
Mutual labels:  rollup, rollup-plugin
web-config
A Rollup configuration to build modern web applications with sweet features as for example SCSS imports, Service Worker generation with Workbox, Karma testing, live reloading, coping resources, chunking, treeshaking, Typescript, license extraction, filesize visualizer, JSON import, budgets, build progress, minifying and compression with brotli a…
Stars: ✭ 17 (-70.18%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-generate-package-json
Generate package.json file with packages from your bundle using Rollup
Stars: ✭ 29 (-49.12%)
Mutual labels:  rollup, rollup-plugin
apex-rollup
Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
Stars: ✭ 133 (+133.33%)
Mutual labels:  rollup
zksync-dapp-checkout
zkCheckout — trustable permissionless DeFi payment gateway. Brand new zkSync dApp w/t all L2 perks: fast&cheap transfers / simple&quick withdrawal
Stars: ✭ 37 (-35.09%)
Mutual labels:  rollup
ontwik-ui
ontwik-ui - A headless UI library
Stars: ✭ 52 (-8.77%)
Mutual labels:  rollup
fliphub
the easiest app builder
Stars: ✭ 30 (-47.37%)
Mutual labels:  rollup
rollup-plugin-glob-import
A rollup plugin to use glob-star.
Stars: ✭ 18 (-68.42%)
Mutual labels:  rollup

rollup-plugin-external-globals

Build Status codecov install size

Transform external imports into global variables like Rollup's output.globals option. See rollup/rollup#2374

Installation

npm install -D rollup-plugin-external-globals

Usage

import externalGlobals from "rollup-plugin-external-globals";

export default {
  input: ["entry.js"],
  output: {
    dir: "dist",
    format: "es"
  },
  plugins: [
    externalGlobals({
      jquery: "$"
    })
  ]
};

The above config transforms

import jq from "jquery";

console.log(jq(".test"));

into

console.log($(".test"));

It also transforms dynamic import:

import("jquery")
  .then($ => {
    $ = $.default || $;
    console.log($(".test"));
  });

// transformed
Promise.resolve($)
  .then($ => {
    $ = $.default || $;
    console.log($(".test"));
  });

Note: when using dynamic import, you should notice that in ES module, the resolved object is aways a module namespace, but the global variable might be not.

Note: this plugin only works with import/export syntax. If you are using a module loader transformer e.g. rollup-plugin-commonjs, you have to put this plugin after the transformer plugin.

API

This module exports a single function.

createPlugin

const plugin = createPlugin(
  globals: Object | Function,
  {
    include?: Array,
    exclude?: Array,
    dynamicWrapper?: Function
  } = {}
);

globals is a moduleId/variableName map. For example, to map jquery module to $:

const globals = {
  jquery: "$"
}

or provide a function that takes the moduleId and returns the variableName.

const globals = (id) => {
  if (id === "jquery") {
    return "$";
  }
}

include is an array of glob patterns. If defined, only matched files would be transformed.

exclude is an array of glob patterns. Matched files would not be transformed.

dynamicWrapper is used to specify dynamic imports. Below is the default.

const dynamicWrapper = (id) => {
  return `Promise.resolve(${id})`;
}

Virtual modules are always transformed.

Changelog

  • 0.6.1 (Oct 21, 2020)

    • Fix: add an extra assignment when exporting globals.
  • 0.6.0 (Aug 14, 2020)

    • Breaking: bump to rollup@2.
  • 0.5.0 (Dec 8, 2019)

    • Add: dynamicWrapper option.
    • Add: now globals can be a function.
    • Bump dependencies/peer dependencies.
  • 0.4.0 (Sep 24, 2019)

    • Add: transform dynamic imports i.e. import("foo") => Promise.resolve(FOO).
  • 0.3.1 (Jun 6, 2019)

    • Fix: all export-from statements are incorrectly transformed.
    • Bump dependencies.
  • 0.3.0 (Mar 25, 2019)

    • Fix: temporary variable name conflicts.
    • Breaking: transform virtual modules. Now the plugin transforms proxy modules generated by commonjs plugin.
    • Bump dependencies.
  • 0.2.1 (Oct 2, 2018)

    • Fix: don't skip export statement.
  • 0.2.0 (Sep 12, 2018)

    • Change: use transform hook.
    • Add: rewrite conflicted variable names.
    • Add: handle export from.
  • 0.1.0 (Aug 5, 2018)

    • Initial release.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].