一覧へ戻る
piuccio/rollup-plugin-amd(新しいタブで開きます)
主要言語: JavaScript
Convert AMD files to ES2016 modules
- star 数
- 23
- watcher 数
- 2
- fork 数
- 10
- issue 数
- 2
- 最終更新
- 2022/12/02
主要言語: JavaScript
Convert AMD files to ES2016 modules
Convert AMD files to ES2016 modules, so they can be included in a Rollup bundle.
npm install --save-dev rollup-plugin-amd
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();
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.
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 issuesconverter: { sourceMap: true, // Default someOtherOption: someOtherOptionValue ... }
rewire allows to modify the imported path of define dependencies.
moduleId is the dependency IDparentPath is the path of the file including the dependencydefine(['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 }); } }) ] });
Apache-2.0