Gulp AMD Bundler

1.32.0 · abandoned · verified Tue Apr 21

gulp-amd-bundler is a Gulp plugin designed to consolidate an Asynchronous Module Definition (AMD) module and its dependencies into a single output file. Originally catering to projects utilizing AMD loaders like RequireJS, it was instrumental in optimizing browser-side JavaScript delivery by reducing HTTP requests. The package is currently at version 1.32.0 and appears to be unmaintained, with its `engines` field specifying Node.js `>= 0.8.0`, a version released over a decade ago. In the modern JavaScript ecosystem, AMD has largely been superseded by ECMAScript Modules (ESM) and more advanced bundlers such as Webpack, Rollup, and Parcel, which offer superior tree-shaking, code splitting, and broader module format support. This plugin's relevance is now primarily for legacy AMD-based projects requiring maintenance or migration rather than new development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic Gulp task using `gulp-amd-bundler` to bundle simple AMD modules. It includes dummy AMD modules and a Gulpfile that uses `require` for compatibility. The bundled output is concatenated into `bundle.js` for browser consumption.

const gulp = require('gulp');
const amdBundler = require('gulp-amd-bundler');
const concat = require('gulp-concat');

// Dummy AMD module for demonstration
// Save this as `src/lib/my-module.js`
/*
define('my-module', [], function() {
  return { name: 'My Module', version: '1.0' };
});
*/

// Entry point AMD module
// Save this as `src/main.js`
/*
define(['./lib/my-module'], function(myModule) {
  console.log(`Main module loaded. ${myModule.name} v${myModule.version}`);
  return {
    start: function() {
      document.getElementById('app').textContent = `App started with ${myModule.name}`;
      console.log('App started!');
    }
  };
});
*/

function bundleAmd() {
  return gulp.src('src/main.js')
    .pipe(amdBundler({
      // Options for gulp-amd-bundler, e.g., base path for modules
      // Note: This plugin's options are not extensively documented
      // and might require an underlying AMD loader configuration.
      // For a simple single file, options might not be strictly needed.
    }))
    .pipe(concat('bundle.js')) // Combine the bundled AMD output into one file
    .pipe(gulp.dest('dist'));
}

// An example task to prepare a basic HTML file to load the bundle
function html() {
  return gulp.src('src/index.html')
    .pipe(gulp.dest('dist'));
}

exports.bundle = gulp.series(bundleAmd, html);
exports.default = exports.bundle;

// To run this:
// 1. npm init -y
// 2. npm install gulp gulp-amd-bundler gulp-concat --save-dev
// 3. Create `src/lib/my-module.js` and `src/main.js` with the content above.
// 4. Create `src/index.html` with a script tag to load `dist/bundle.js` and an element with id='app'.
// 5. Run `gulp bundle`

view raw JSON →