Home

Awesome

rollup-plugin-iife

Build Status codecov install size

Currently (rollup@0.65), rollup doesn't support code splitting with IIFE output. This plugin would transform ES module output into IIFEs.

Installation

npm install -D rollup-plugin-iife

Usage

import iife from "rollup-plugin-iife";

export default {
  input: ["entry.js", "entry2.js"],
  output: {
    dir: "dist",
    format: "es",
    globals: {
      vue: "Vue"
    }
  },
  externals: ["vue"],
  plugins: [iife()]
};

Define global variables for external imports

You can define global variables with output.globals just like before. You can also specify them with the plugin option names.

The plugin would first lookup names option then output.globals.

API

This module exports a single function.

iife

iife({
  names?: Function|Object,
  sourcemap?: Boolean,
  prefix?: String,
  strict?: Boolean
}) => PluginInstance

Create the plugin instance.

If names is a function, the signature is:

(moduleId: String) => globalVariableName: String

If names is an object, it is a moduleId/globalVariableName map. moduleId can be relative to the output folder (e.g. ./entry.js), the plugin would resolve it to the absolute path.

If the plugin can't find a proper variable name, it would generate one according to its filename with camelcase.

If sourcemap is false then don't generate the sourcemap. Default: true.

When prefix is defined, it will be used to prefix auto-generated variable names. It doesn't prefix names defined in the names option. It doesn't prefix external imports.

If strict is true then add 'use strict'; directive to the IIFE. Default: true.

Related projects

Changelog