Use Gulp to wrap javascript files with a IIFE Use Gulp to wrap javascript files with a IIFE angularjs angularjs

Use Gulp to wrap javascript files with a IIFE


Use the gulp-wrap plugin with a simple template:

var wrap = require("gulp-wrap");gulp.src("./src/*.js")    .pipe(wrap('(function(){\n"use strict";\n<%= contents %>\n})();'))    .pipe(gulp.dest("./dist"));

This will wrap each file's contents with the template:

(function(){"use strict";//contents hereā€¦})();

You can also store the template on the filesystem, rather than embedding it in your gulpfile, and call gulp-wrap using wrap({src: 'path/to/template'})