Gulp: enclose a gulp-tabular result in an unnamed function

I have several files that I connect to and rearrange with gulp-babel. I would like to put all the results in an anonymous namespace function:

(function() {

    // my file.js content inside

})();

I tried:

gulp.src([
    './open-scope.js', 
    './file-1.js',
    './file-2.js',
    './file-3.js',
    './close-scope.js' 
])
.pipe(gp_concat('file.js'))
.pipe(babel({ presets: ['env'] }))
.pipe(gulp.dest('static/general/es6/html'));

My open-scope.js:

(function() {

My close-scope.js:

})();

But part of the .pipe(babel())prefix of the transferred file is with a variable _createClassand function _classCallCheck, and I do not want them to be in the global scope.

I guess I need

.pipe(prepend('open-scope.js')).pipe(append('close-scope.js'))

between mine .pipe(babel())and .pipe(gulp.dest()).

I know how to concatenate files using fs, but I need a gulp solution.

+4
source share

Source: https://habr.com/ru/post/1692295/


All Articles