@makeomatic/gulp-wrap-js

1.0.2 • Public • Published

gulp-wrap-js

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.

Usage

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");

gulp.src("./src/*.js")
    .pipe(sourcemaps.init())
        .pipe(wrapJS('define(function () {%= body %})'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest("./dist"));

API

wrapJS(template, format)

template

Type: String
Required

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.

format

Type: Object Default: escodegen.FORMAT_DEFAULTS

escodegen output format options.

License

MIT License

Package Sidebar

Install

npm i @makeomatic/gulp-wrap-js

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

7.29 kB

Total Files

5

Last publish

Collaborators

  • avvs
  • freele