T
T
ttm2019-11-19 11:20:07
JavaScript
ttm, 2019-11-19 11:20:07

How to connect babel polyfills?

There is a galp and a babel.
No webpack, brazify, etc.
A library is developed with the maximum minimum file size.
There was a need to use promises.
If you add babel polyfills to gulp task

gulp.task('build', () => {
    return gulp.src([
        'node_modules/babel-polyfill/dist/polyfill.js',
        'app.js'
    ])
    //...
})

Then all polyfills are shoved, but only promises are needed.
What options exist to pull out pure promises from polyfills?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ttm, 2019-11-19
@TouchTheMind

solution for anyone interested

// promise.js
_Promise = require('babel-runtime/core-js/promise').default;

// gulpfile.js
const gulp = require('gulp');
const concat = require('gulp-concat');
const header = require('gulp-header');
const webpack = require('webpack-stream');

gulp.task('build-promise' ,() =>{
    return gulp.src('promise.js')
        .pipe(webpack())
        .pipe(header(`
            let _Promise;
        `))
        // ....
        .pipe(concat('promise.js'))
        .pipe(gulp.dest('dist'));
})

Then you can do anything with this js, you can wrap it for example
Is there a better solution? - Write ;)

F
FLighter, 2019-11-19
@flighter7

You here , look at useBuiltIns and corejs
I.e. no need to insert polyfills in the code, babel will insert them when he sees them. Be sure to install the core-js package , it won't build correctly without it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question