in JavaScript ~ read.

Gulp plugin for wrapping JavaScript code with source maps support

View on GitHub

NPM version Build Status Dependency Status

When using classic templating solutions (like Lo-Dash / Underscore templates / own regexps / etc.) for wrapping JavaScript code, you're manipulating code as strings under the hood, and so losing any inner structure and location information. Such approach is used in gulp-wrap, gulp-wrap-amd, gulp-wrap-umd and that's why source maps are not currently supported in any of them.

In opposite, this plugin is based on AST templating estemplate library, and allows to wrap your JavaScript code into given template (UMD / AMD / whatever) with preserved locations for source maps generation.

Check out gulp-sourcemaps for detailed instructions on working with source maps enabled plugins in Gulp.


First, install gulp-wrap-js as a development dependency:

npm install --save-dev gulp-wrap-js

Then, add it to your gulpfile.js:

var sourcemaps = require('gulp-sourcemaps');
var wrapJS = require("gulp-wrap-js");

        .pipe(wrapJS('define(function () {%= body %})'))


wrapJS(template, format)


Type: String

Template you wish to wrap your code with. Check out estemplate docs for all the possible substitution markers.

Note that in gulp-wrap-js you have only body array of statements passed to template as data.


Type: Object
Default: escodegen.FORMAT_DEFAULTS

escodegen output format options.


MIT License