@buxlabs/amd-to-es6

中文文档
0.16.4发布于 2025/12/02MITCommonJS近 30 天下载 2.2万

convert amd to es6

原始使用文档
文档目录12 节
  1. Table of Contents
  2. Background
  3. Install
  4. Usage
  5. cli
  6. Options
  7. node
  8. Examples
  9. Maintainers
  10. Contributing
  11. Credits
  12. License

AMD to ES converter

npm Codeship

AMD (Asynchronous Module Definition) to ES (EcmaScript) Module converter

Table of Contents

Background

AMD was very popular and used in many big applications worldwide. ES Module standard was created much later and with the rise of various bundlers and transpilers it became possible to write modern code with more concise syntax. This tool was created to fill the migration gap, as other tools were not handling some of the edge cases. It should handle most of existing code out of the box.

This tool exposes both a cli and a programmatic interface.

Install

npm install -g @buxlabs/amd-to-es6

Usage

cli

Convert a single file with:

amdtoes6 app.js > app-es6.js

Convert multiple files in given dir with:

amdtoes6 --src=src --dest=build

Convert multiple files in given dir recursively with:

amdtoes6 --src=src --dest=build --glob=**/*.js

Convert multiple files and replace them with:

amdtoes6 --src=src --replace

Options


  Usage: amdtoes6 [options]

  Options:

    -s, --src <dirname>     Directory of the source files
    -d, --dest <dirname>    Directory of the destination files
    -g, --glob [glob]       Glob pattern for the src to match for input files
    -r, --recursive         Set glob pattern to **/*.js with no hassle
    -b, --beautify          Beautify the output
    --replace           Replace the input files with results
    --suffix <string>   Replace suffix of the files
    --quotes            Single, double or auto quotes in the output

node

Convert a single file with:

const amdtoes6 = require('@buxlabs/amd-to-es6');
const source = 'define({ hello: 'world' });';
const result = amdtoes6(source); // export default { hello: 'world' };

Examples

AMD

define([
    'core/view',
    'subapp/hello/template/layout'
], function (View, template) {
    'use strict';

    return View.extend({
        template: template
    });

});

ES

import View from 'core/view';
import template from 'subapp/hello/template/layout';

export default View.extend({
    template: template
});

AMD

define(function (require) {
    'use strict';

    var Marionette = require('marionette');

    return Marionette.Object.extend({
        initialize: function () {
            console.log('hello world');
        }
    });
});

ES

import Marionette from 'marionette';

export default Marionette.Object.extend({
    initialize: function () {
        console.log('hello world');
    }
});

There are more examples in the test/fixture directory

Maintainers

@emilos.

Contributing

All contributions are highly appreciated! Open an issue or a submit PR.

The lib follows the tdd approach and is expected to have a high code coverage.

Credits

https://github.com/jonbretman/amd-to-as6

License

MIT © buxlabs

版本与发布记录

@buxlabs/amd-to-es6 共发布 37 个版本,首次发布于 2016/11/27;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.16.4latest2025/12/0211 个月前
0.16.32022/01/204 年前
0.16.12021/07/155 年前
0.16.02020/11/026 年前
0.15.22020/05/186 年前
0.15.12020/05/186 年前

关于 @buxlabs/amd-to-es6 的常见问题

@buxlabs/amd-to-es6 是什么?

convert amd to es6

如何安装 @buxlabs/amd-to-es6?

在项目目录运行 npm install @buxlabs/amd-to-es6,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 amdtoes6,可以用 npx amdtoes6 直接运行。

@buxlabs/amd-to-es6 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/buxlabs__amd-to-es6 是否存在。

@buxlabs/amd-to-es6 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@buxlabs/amd-to-es6 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.15.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@buxlabs/amd-to-es6 可以商用吗?

@buxlabs/amd-to-es6 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@buxlabs/amd-to-es6 的下载量有多少?

根据 npm 官方下载统计,@buxlabs/amd-to-es6 在 2026/10/09 – 2026/11/07 这 30 天内被下载 21,916 次,日均约 731 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@buxlabs/amd-to-es6 还在维护吗?

最新版本 0.16.4 发布于 2025/12/02(11 个月前);至今共发布 37 个版本,其中过去 12 个月发布了 1 个;首次发布于 2016/11/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。