Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piuccio/rollup-plugin-amd
Convert AMD files to ES2016 modules
https://github.com/piuccio/rollup-plugin-amd
Last synced: about 1 month ago
JSON representation
Convert AMD files to ES2016 modules
- Host: GitHub
- URL: https://github.com/piuccio/rollup-plugin-amd
- Owner: piuccio
- License: other
- Created: 2016-09-28T16:19:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T04:21:12.000Z (about 2 years ago)
- Last Synced: 2024-04-08T16:24:50.125Z (8 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 23
- Watchers: 2
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome - amd - Convert AMD modules to ES6. (Plugins / Modules)
README
# 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
```js
import { rollup } from 'rollup';
import amd from 'rollup-plugin-amd';rollup({
entry: 'main.js',
plugins: [
amd()
]
});
```The configuration above converts
```js
define(['utils/array', 'react'], function (array, React) {
React.render();
});
```into
```js
import array from './javascripts/utils/array';
import React from './node_modules/react/react.js';React.render();
```### Options
```js
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: { sourceMap: true }
rewire: function (moduleId, parentPath) { // Optional, Default: false
return './basePath/' + moduleId;
}
})
]
});
```* __converter__ options to pass down to the AMD to ES6 [converter](https://github.com/buxlabs/amd-to-es6#options).
- Please note that `converter` option is set to `{ sourceMap: true }` by default. If you want to disable sourcemap, you can set it as `{ sourceMap: false }`. However, this may bring some [sourcemap related issues](https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect)
- Other options for converter can be passed down in the same way as we set the sourcemap
```js
converter: {
sourceMap: true, // Default
someOtherOption: someOtherOptionValue
...
}
```* __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```js
define(['lodash'], function (_) {});
```becomes
```js
import _ from './basePath/lodash';
```If you're converting AMD modules from requirejs, you can use [node-module-lookup-amd](https://github.com/dependents/node-module-lookup-amd) to rewire your dependencies
```js
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