I have a gulp task to compile ES6 code into ES5 using babel and browserify. but when compiling it compiles all the other things except functions().
my gulp task code.
gulp.task('convert', function() {
return browserify({ entries: './src/app.js', debug: true })
.transform("babelify", { "presets": ["es2015"] })
.bundle()
.pipe(plumber({
errorHandler: function (err) {
notify.onError({
title: "Gulp error in " + err.plugin,
message: err.toString()
})(err);
}
}))
.pipe(source( 'app.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./tmp'))
.pipe(browserSync.reload({stream: true}));
});
my js file:
let title = 'this is my app 3';
let test = 'test';
document.getElementById("box").innerHTML = title;
document.getElementById("box2").innerHTML = test;
var tests = ()=>{
alert('hello');
}
converted file :
!function e(r,t,n){function o(u,f){if(!t[u]){if(!r[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=t[u]={exports:{}};r[u][0].call(a.exports,function(e){var t=r[u][1][e];return o(t||e)},a,a.exports,e,r,t,n)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(e,r,t){"use strict";document.getElementById("box").innerHTML="this is my app 3",document.getElementById("box2").innerHTML="test"},{}]},{},[1]);
//# sourceMappingURL=maps/app3.js.map
when I use the function it says tests is not defined. really need help:/