I have an angular app that has a lot of .js
files.
It's boring to add an IIFE to each file and then add 'use strict'
.
Is there any way to automate this? I use gulp to run tasks.
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'})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With