Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: How to use polyfills #219

Open
sf-steve opened this issue Jul 30, 2021 · 0 comments
Open

Documentation: How to use polyfills #219

sf-steve opened this issue Jul 30, 2021 · 0 comments

Comments

@sf-steve
Copy link

sf-steve commented Jul 30, 2021

I am failing miserably to get gulp-babel to pollyfil instance methods such as Array.prototype.includes

Looking through the internet, i see various docs, such as https://babeljs.io/docs/en/usage/#polyfill but no indication of how to use this with gulp-babel

I have a very basic setup:

package.json

{
    ...
      "dependencies": {},
      "devDependencies": {
        "@babel/core": "^7.14.8",
        "@babel/preset-env": "^7.14.8",
        "gulp": "latest",
        "gulp-autoprefixer": "latest",
        "gulp-babel": "^8.0.0",
        "gulp-clean-css": "latest",
        "gulp-concat": "latest",
        "gulp-minify": "latest",
        "gulp-rename": "latest",
        "gulp-sass": "latest"
      },
    ...
}

gulpfile.js

var themepath = "xx"
var gulp = require('gulp');
var babel = require('gulp-babel');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');
var minify = require('gulp-minify');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');


gulp.task('js', function () {
	return gulp.src(themepath + 'assets/src/js/**/*.js')
		.pipe(concat('main.js'))
		.pipe(babel({
			presets: ['@babel/preset-env']
		}))
		.pipe(minify({
			ext: {
				min: '.min.js'
			}
		}))
		.on('error', handleError)
		.pipe(gulp.dest(themepath + 'assets/dist/js'))
});

After running the js task, dist/js/main.js will have arrow functions converted to ES5, but calls to Array.prototype.includes will stll exist, and there is no pollyfil code either.

I can of course get around this issue by manually copying selected polyfills into a polyfills.js file in the js folder, but this is prone to errors, and somewhat negates the purpose of using babel in the first place.

I expect this is a symple config issue, that could be solved by a document update. I (and many other internet strangers) would appreciate it if this can be solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant