rollup-plugin-amd
raw JSON → 4.0.0 verified Mon Apr 27 auth: no javascript maintenance
Rollup plugin that converts AMD modules (e.g., RequireJS) to ES2016 modules for bundling. Version 4.0.0 requires Node >=8 and Rollup 1.x+. It wraps the amd-to-es6 converter and provides include/exclude filtering and a rewire function to map AMD dependency IDs to file paths. Compared to manual conversion, it automates the transform within the Rollup build pipeline. Release cadence is low; last major update was in 2019.
Common errors
error Error: Cannot find module 'rollup-plugin-amd' ↓
cause Forgot to install the plugin or are using a CJS require in an ESM-only package.
fix
Run 'npm install --save-dev rollup-plugin-amd' and use import syntax.
error The 'code' argument must be a string in amd-to-es6 ↓
cause The plugin received a non-string file content, possibly due to a virtual file plugin conflict.
fix
Ensure the file being transformed is a plain JavaScript file.
Warnings
breaking Pugin v4.0.0 only supports Rollup 1.x. May not work with Rollup 2+ or newer. ↓
fix Consider using an alternative plugin that supports modern Rollup, or downgrade Rollup to 1.x.
deprecated The package uses the deprecated 'rollup.watch' in older versions. ↓
fix Upgrade to v4.0.0 or later.
gotcha The 'rewire' function must return a relative path; otherwise imports may be resolved incorrectly. ↓
fix Ensure the returned path is relative to the current file, not absolute.
Install
npm install rollup-plugin-amd yarn add rollup-plugin-amd pnpm add rollup-plugin-amd Imports
- default (amd) wrong
const amd = require('rollup-plugin-amd')correctimport amd from 'rollup-plugin-amd' - amd (named) wrong
import { amd } from 'rollup-plugin-amd'correctimport amd from 'rollup-plugin-amd' - Plugin as Rollup plugin wrong
new amd()correctamd({ include: 'src/**', exclude: ['node_modules/**'] })
Quickstart
import { rollup } from 'rollup';
import amd from 'rollup-plugin-amd';
async function build() {
const bundle = await rollup({
input: 'main.js',
plugins: [
amd({
include: 'src/**',
exclude: ['node_modules/**'],
rewire: (moduleId, parentPath) => {
// Map AMD module IDs to file paths
return './javascripts/' + moduleId;
}
})
]
});
await bundle.write({ file: 'bundle.js', format: 'iife' });
}
build().catch(console.error);