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-iifeUsage
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 (trueby default)trimCode: a boolean indicating whether to remove leading & trailing whitespace from the code (trueby default)prependSemicolon: a boolean indicating whether to prepend a semicolon as statement terminator before the IIFE (trueby default)bindThis: a boolean indicating whether to prepend.bind(this)to the IIFE (falseby default)
var gulp = require("gulp");
var iife = require("gulp-iife");
gulp.task("default", function() {
return gulp.src("src/input.js")
.pipe(iife({
useStrict: false,
trimCode: 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.