M
M
Maxim Shimko2019-09-19 12:57:49
gulp.js
Maxim Shimko, 2019-09-19 12:57:49

How to set up babel along with gulp?

Hello. You need to configure babel so that the necessary polyfills are loaded via gulp. The intuitive documentation hasn't given me an answer to this question for a day now.
Needed: support for all new js features (ES19), converting them to ES5. support for promises, methods such as Object.values, Array.Flat(), etc., support for legacy code, i.e. lack of "strict mode". I would like to get 1 js file at the output, which is already ready for use in production.
What is now:

return gulp.src(files)
  .pipe(sourcemaps.init())
  .pipe(babel({presets: , plugins: ["transform-remove-strict-mode", "transform-runtime"], compact: true}))
  .pipe(concat(config.name + '.min.js'))
  .pipe(uglify())
  .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
  .pipe(sourcemaps.write('./'))
  .pipe(gulp.dest(__dirname + '/Builds'));

Now there are require functions in the code, apparently you still need to somehow embed babel-runtime in the output, but I don’t understand how. Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question