gulp-babel-globals
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
Gulp plugin for babel-globals that allows you to define global variable names for Babel modules during a Gulp build pipeline. Version 2.0.0 is the latest stable release, with no frequent updates. It wraps babel-globals (v2.x) to integrate with Gulp streams. Differentiators: it provides a Gulp-friendly API for handling ES6 module globals, which is useful for legacy builds or specific bundling needs. Alternatives include using Babel directly with custom plugins.
Common errors
error Cannot find module 'babel-globals' ↓
cause babel-globals is a peer dependency that must be installed separately.
fix
Run 'npm install babel-globals' alongside gulp-babel-globals.
error TypeError: babelGlobals is not a function ↓
cause Incorrect import: using named import instead of default import.
fix
Use 'const babelGlobals = require("gulp-babel-globals")' or 'import babelGlobals from "gulp-babel-globals"'.
Warnings
gotcha The plugin only processes files ending in .js; other extensions are ignored silently. ↓
fix Ensure input files have .js extension or configure gulp.src accordingly.
deprecated The 'bundleFileName' option is required but not validated; missing it may cause errors. ↓
fix Always provide a 'bundleFileName' option in the options object.
gotcha This plugin is not compatible with Babel 7+ because babel-globals has not been updated. ↓
fix Use an alternative approach for Babel 7 or higher, such as custom Gulp transforms.
Install
npm install gulp-babel-globals yarn add gulp-babel-globals pnpm add gulp-babel-globals Imports
- default wrong
const babelGlobals = require('gulp-babel-globals')correctimport babelGlobals from 'gulp-babel-globals' - gulpBabelGlobals
import * as gulpBabelGlobals from 'gulp-babel-globals' - default wrong
import { babelGlobals } from 'gulp-babel-globals'correctconst babelGlobals = require('gulp-babel-globals')
Quickstart
const gulp = require('gulp');
const babelGlobals = require('gulp-babel-globals');
gulp.task('globals', () => {
return gulp.src('src/**/*.js')
.pipe(babelGlobals({ bundleFileName: 'myBundle.js' }))
.pipe(gulp.dest('dist'));
});