Package Exports
- gulp-iife
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-iife) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
gulp-iife
A Gulp plugin for wrapping JavaScript code within immediately invoked function expressions (IIFEs).
Install
$ npm install --save-dev gulp-iife
Usage
var gulp = require("gulp");
var iife = require("gulp-iife");
gulp.task("default", function() {
return gulp.src("src/input.js")
.pipe(iife())
.pipe(gulp.dest("dist"));
});
Input file:
var greeting = "Hello, World!";
console.log(greeting);
Output file:
;(function() {
"use strict";
var greeting = "Hello, World!";
console.log(greeting);
}());
Options
You can configure the following options:
useStrict
- A boolean indicating whether to prepend a
"use strict";
directive. true
by default
- A boolean indicating whether to prepend a
trimCode
- A boolean indicating whether to remove leading & trailing whitespace from the code.
true
by default
prependSemicolon
- A boolean indicating whether to prepend a semicolon as statement terminator before the IIFE.
true
by default
bindThis
- A boolean indicating whether to append
.bind(this)
to the IIFE. Setting this value totrue
makes the surrounding global object available to the function, which is usually not the case in strict mode. false
by default
- A boolean indicating whether to append
params
- An array of parameter names to be accepted by the IIFE. If the
args
option is not specified, the arguments of the function call will use the same identifiers.
- An array of parameter names to be accepted by the IIFE. If the
args
- An array of arguments to be passed into the IIFE.
var gulp = require("gulp");
var iife = require("gulp-iife");
gulp.task("default", function() {
return gulp.src("src/input.js")
.pipe(iife({
useStrict: false,
prependSemicolon: false
}))
.pipe(gulp.dest("dist"));
});
Input file:
var greeting = "Hello, World!";
console.log(greeting);
Output file:
(function() {
var greeting = "Hello, World!";
console.log(greeting);
}());
Formatting
In the spirit of Gulp plugins, gulp-iife does one thing and one thing only: adding wrapping IIFEs.
If you'd like the resulting code to be neatly indented or otherwise formatted, pipe the output to another Gulp plugin which formats the JavaScript code, such as gulp-esformatter.
Changelog
The changelog can be found in CHANGELOG.md.