# gulp-iife

> Wraps JavaScript code within an immediately invoked function expression.

Latest version **0.4.0** (published 2018-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-iife
pnpm add gulp-iife
yarn add gulp-iife
bun add gulp-iife
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2018-10-31 |
| First published | 2015-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Marius Schulz |
| Maintainers | mariusschulz |
| Keywords | gulpplugin, javascript, ecmascript, js, iife, siaf, immediately, invoked, function, expression |

## Links

- npm: https://www.npmjs.com/package/gulp-iife
- Repository: https://github.com/mariusschulz/gulp-iife
- Issues: https://github.com/mariusschulz/gulp-iife/issues
- npm.io page: https://npm.io/package/gulp-iife

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [through2](https://npm.io/package/through2.md) ^2.0.0
- [source-map](https://npm.io/package/source-map.md) ^0.5.3
- [vinyl-sourcemaps-apply](https://npm.io/package/vinyl-sourcemaps-apply.md) ^0.2.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.4.0 (latest) — 2018-10-31
- 0.3.0 — 2016-04-14
- 0.2.4 — 2015-11-04
- 0.2.3 — 2015-11-04
- 0.2.2 — 2015-11-04
- 0.2.1 — 2015-11-04
- 0.2.0 — 2015-11-01
- 0.1.0 — 2015-09-06
- 0.0.7 — 2015-07-14
- 0.0.6 — 2015-05-04
- 0.0.5 — 2015-03-29
- 0.0.4 — 2015-03-29
- 0.0.3 — 2015-03-29
- 0.0.2 — 2015-03-21
- 0.0.1 — 2015-03-21

## README

# gulp-iife

A Gulp plugin for wrapping JavaScript code within immediately invoked function expressions (IIFEs).


## Install

```
$ npm install --save-dev gulp-iife
```


## Usage

```js
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:

```js
var greeting = "Hello, World!";
console.log(greeting);
```

Output file:

```js
;(function() {
"use strict";

var greeting = "Hello, World!";
console.log(greeting);
}());
```


## Options

You can configure the following options:

- [`useStrict`](#usestrict)
- [`trimCode`](#trimcode)
- [`prependSemicolon`](#prependsemicolon)
- [`bindThis`](#bindthis)
- [`params`](#params)
- [`args`](#args)

Here's an example specifying all available options:

```js
var gulp = require("gulp");
var iife = require("gulp-iife");

gulp.task("default", function() {
    return gulp.src("src/input.js")
        .pipe(iife({
            useStrict: true,
            trimCode: true,
            prependSemicolon: false,
            bindThis: false,
            params: ["window", "document", "$", "undefined"],
            args: ["window", "document", "jQuery"]
        }))
        .pipe(gulp.dest("dist"));
});
```

Input file:

```js
var greeting = "Hello, World!";
console.log(greeting);
```

Output file:

```js
(function(window, document, $, undefined) {
"use strict";

var greeting = "Hello, World!";
console.log(greeting);
}(window, document, jQuery));
```


### `useStrict`

A boolean indicating whether to prepend a `"use strict";` directive to the function body.

- **Default**: `true`


### `trimCode`

A boolean indicating whether to remove leading & trailing whitespace from the code.

- **Default**: `true`


### `prependSemicolon`

A boolean indicating whether to prepend a semicolon as statement terminator before the IIFE.

- **Default**: `true`


### `bindThis`

A boolean indicating whether to append `.bind(this)` to the IIFE. Setting this value to `true` makes the surrounding global object available to the function, which is usually not the case in strict mode.

- **Default**: `false`


### `params`

An array of parameter names to be accepted by the IIFE. If the `args` option is not specified, the same identifiers will be passed as arguments of the function call.

- **Default**: none


### `args`

An array of argument names to be passed into the IIFE. If the `params` option is not specified, the parameters of the function will have the same names as the arguments passed.

- **Default**: none


## Source Maps

*gulp-iife* supports source maps, which means you can use it like this:

```js
var gulp = require("gulp");
var iife = require("../gulp-iife/lib");
var sourcemaps = require("gulp-sourcemaps");

gulp.task("default", function() {
    return gulp.src("src/input.js")
        .pipe(sourcemaps.init())
        .pipe(iife({ }))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest("./built"));
});
```


## Changelog

The changelog can be found in [CHANGELOG.md](https://github.com/mariusschulz/gulp-iife/blob/master/CHANGELOG.md).


## 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](https://github.com/sindresorhus/gulp-esformatter).

---
_Source: https://npm.io/package/gulp-iife · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
