K
K
korner-brazers2021-09-11 12:59:27
gulp.js
korner-brazers, 2021-09-11 12:59:27

Gulp how to bake ES6 under ES5?

I am making a project on ES6, the project uses import and exrpot.
Everything would be fine, but you need to bake a single file for old browsers, but I can’t find how to do it.

Here is an excerpt from gulpfile.js

gulp.task('merge', function(){
    return (
        gulp.src(srcFolder+"app.js")
            .pipe(plumber())
            // Notice the name change.
            .pipe(concat("app.js"))
            .pipe(
                babel({
                    presets: ["@babel/env"]
                })
            )
            .pipe(gulp.dest(dstFolder))
    )
});


At the output I have:

"use strict";

var _math = _interopRequireDefault(require("./utils/math"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

console.log(_math["default"].twoPlusTwo());


Even in a modern browser I get an error on the require () function. Because this function does not exist, and what can we say about es5.

How can I bake a single file for the browser?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
korner-brazers, 2021-09-11
@korner-brazers

All figured out, used rollup.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question