rollup-plugin-amd
Convert AMD files to ES2016 modules, so they can be included in a Rollup bundle.
Installation
npm install --save-dev rollup-plugin-amd
Usage
import { rollup } from 'rollup';
import amd from 'rollup-plugin-amd';
rollup({
entry: 'main.js',
plugins: [
amd()
]
});
The configuration above converts
define(['utils/array', 'react'], function (array, React) {
React.render();
});
into
import array from './javascripts/utils/array';
import React from './node_modules/react/react.js';
React.render();
Options
import { rollup } from 'rollup';
import amd from 'rollup-plugin-amd';
rollup({
entry: 'main.js',
plugins: [
amd({
include: 'src/**',
exclude: [ 'node_modules/**' ],
converter: {},
rewire: function (moduleId, parentPath) {
return './basePath/' + moduleId;
}
})
]
});
define(['lodash'], function (_) {});
becomes
import _ from './basePath/lodash';
If you're converting AMD modules from requirejs, you can use node-module-lookup-amd to rewire your dependencies
import { rollup } from 'rollup';
import amd from 'rollup-plugin-amd';
import lookup from 'module-lookup-amd';
rollup({
entry: 'main.js',
plugins: [
amd({
rewire: function (moduleId, parentPath) {
return lookup({
partial: moduleId,
filename: parentPath,
config: 'path-to-requirejs.config'
});
}
})
]
});
License
Apache-2.0