Registry / devops / babel-plugin-iife-wrap

babel-plugin-iife-wrap

JSON →
library1.1.0jsnpmunverified

A Babel plugin that wraps the entire file content in an Immediately Invoked Function Expression (IIFE) to avoid polluting the global scope. Current stable version 1.1.0 (latest, 2019). Simple and focused: no configuration options, works with Babel 7+. Differentiator: extremely minimal and does one thing—file-level IIFE wrapping, unlike more complex scope isolators.

npm install babel-plugin-iife-wrap
INSTALL
IMPORT
SIG · BABEL-PLUGIN-IIFE-
B
babel-plugin-iife-wrap
devopsjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = require('babel-plugin-iife-wrap');
import iifeWrap from 'babel-plugin-iife-wrap';
CommonJS-only module; no ESM export. Use require() in Node or Babel config.
babel.config.js
module.exports = { plugins: ['iife-wrap'] };
module.exports = { plugins: ['babel-plugin-iife-wrap'] };
In Babel config, the plugin name can be shortened to 'iife-wrap' (without 'babel-plugin-' prefix).
Babel CLI
babel --plugins iife-wrap script.js
babel --plugins babel-plugin-iife-wrap script.js
Same shorthand works for CLI: omit 'babel-plugin-' prefix.

Shows installation and basic usage: input file gets wrapped in IIFE to isolate variables from global scope.

// Install: npm i babel-plugin-iife-wrap --save-dev // Then add to babel.config.js: module.exports = { plugins: ['iife-wrap'] }; // Input (input.js): var x = 1; window.a = x; // Output: ;(function () { var x = 1; window.a = x; }());
Debug
Known issues
gotchaPlugin does not add semicolon before IIFE; output may break if previous file lacks semicolon. Always ensure semicolons or use a separate tool.
fix
Manually add semicolon or use a plugin like 'babel-plugin-add-import-extension' but note that this plugin does not add prefix ';'.
affects: >=1.0.0
gotchaOnly wraps the entire file; does not handle modules or imports. If used with ES modules, output may be invalid JavaScript.
fix
Do not use with ES module syntax (import/export). For modules, consider different scoping techniques.
affects: >=1.0.0
gotchaNo configuration options—cannot customize IIFE parameters or use strict mode. The plugin always wraps in an anonymous function with no arguments.
fix
No workaround; choose another plugin if customization is needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Could not find plugin 'babel-plugin-iife-wrap'
Plugin not installed or not listed in .babelrc plugins array correctly.
fix
Run: npm install babel-plugin-iife-wrap --save-dev. Then in .babelrc: { "plugins": ["iife-wrap"] }
TypeError: this.cache is not a function
Potential compatibility issue with older Babel versions (likely <7).
fix
Ensure @babel/core version 7+ is installed as peer dependency.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
@babel/coreoptionalPeer dependency required for Babel plugin interface.
Agent activity
5 hits · last 30 days
node
4
Resources
babel-plugin-iife-wrap — npm install babel-plugin-iife-wrap · libregistry