Currently ([email protected]), rollup doesn't support code splitting with IIFE output. This plugin would transform ES module output into IIFEs.
npm install -D rollup-plugin-iife
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()]
};
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
.
This module exports a single function.
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
.
<script>
tags).0.7.1 (Feb 16, 2024)
0.7.0 (Oct 20, 2022)
output.dir
is not defined.0.6.0 (Feb 11, 2022)
import.meta.url
. The plugin also throws and error if it sees unconverted import.meta
.0.5.0 (Feb 18, 2021)
'use strict';
directive is inserted by default.strict
option.0.4.0 (Dec 28, 2020)
0.3.1 (Feb 8, 2020)
0.3.0 (Aug 14, 2019)
var
.0.2.1 (Jun 23, 2019)
0.2.0 (Jan 26, 2019)
0.1.2 (Jan 25, 2019)
prefix
option.0.1.1 (Sep 28, 2018)
output.globals
option.0.1.0 (Aug 28, 2018)