gulp-wrap-js

    0.4.1 • 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

    Install

    npm i gulp-wrap-js

    DownloadsWeekly Downloads

    329

    Version

    0.4.1

    License

    MIT

    Last publish

    Collaborators

    • rreverser