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)trimCode
: a boolean indicating whether to remove leading & trailing whitespace from the code (true
by 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 }))
.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.