Skip to content
Convert AMD files to ES2016 modules
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Pass options to amd-to-es6 converter Feb 1, 2019
test Update dependencies and remove support for node 6 Feb 1, 2019
.editorconfig AMD modules Sep 28, 2016
.eslintrc.json Update dependencies and remove support for node 6 Feb 1, 2019
.gitignore AMD modules Sep 28, 2016
.travis.yml Update dependencies and remove support for node 6 Feb 1, 2019
LICENSE.md
README.md typos in readme Jan 27, 2018
package.json 4.0.0 Feb 1, 2019
rollup.config.js

README.md

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/**', // Optional, Default: undefined (everything)
            exclude: [ 'node_modules/**' ], // Optional, Default: undefined (nothing)
            converter: {}, // Optional, Default: undefined
            rewire: function (moduleId, parentPath) { // Optional, Default: false
                return './basePath/' + moduleId;
            }
        })
    ]
});
  • converter options to pass down to the AMD to ES6 converter.

  • rewire allows to modify the imported path of define dependencies.

    • moduleId is the dependency ID
    • parentPath is the path of the file including the dependency
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) { // Optional, Default: false
                return lookup({
                    partial: moduleId,
                    filename: parentPath,
                    config: 'path-to-requirejs.config' // Or an object
                });
            }
        })
    ]
});

License

Apache-2.0

You can’t perform that action at this time.