Name: amd-to-as6
Description: Converts AMD modules into ES6 modules
Created: 2014-09-02 23:26:16.0
Updated: 2018-01-17 16:39:42.0
Pushed: 2017-12-16 06:19:35.0
Homepage: null
Size: 27
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A simple tool for converting AMD modules into ES6 modules, either via the command line or programmatically.
AMD and RequireJS are great, but ES6 modules provide a nicer syntax for writing JS modules and there are so many great tools available now for converting ES6 to ES5 which also allow you to use ES6 syntax/features.
install amd-to-es6 -g
To convert a single file (compiled output sent to stdout):
oes6 my-amd-module.js > my-awesome-es6-module.js
To convert a whole directory:
oes6 --dir src/ --out es6/
If you want to modify the original files just set --out
to the same as --dir
.
oes6 --dir src --out src
If you want some files to be ignored use the --ignore
flag which accepts a glob pattern that is relative to --dir
.
oes6 --dir src --ignore libs/**/*.js
If you want the indentation to be “fixed” then use the --beautify
option which just runs the output through jsbeautify.
If a file cannot be compiled an message will be printed explaining the error and it will be skipped.
Modules without dependencies.
AMD
ne(function () {
return {};
ES6
rt default {};
Modules with dependencies.
AMD
ne(['path/to/a', 'path/to/b'], function (a, b) {
return function (x) {
return a(b(x));
};
ES6
rt a from 'path/to/a';
rt b from 'path/to/b';
rt default function (x) {
return a(b(x));
If you have AMD modules that look like this, where not all dependencies are assigned to parameters but accessed in the module using require
, amdtoes6
will have to create some variable names. You wil probably want to change these.
AMD
ne(['require', 'path/to/a', 'path/to/b'], function (require) {
return function (x) {
var a = require('a');
var b = require('b');
return a(b(x));
};
ES6
rt $__path_to_a from 'path/to/a';
rt $__path_to_b from 'path/to/b';
rt default function (x) {
var a = $__path_to_a;
var b = $__path_to_b;
return a(b(x));
Imports for side-effects.
AMD
ne(['path/to/a', 'path/to/b'], function () {
return {};
ES6
rt 'path/to/a';
rt 'path/to/b';
rt default {};
Without the --beautify
option.
AMD
ne(['path/to/a', 'path/to/b'], function (a, b) {
return function (x) {
return a(b(x));
};
ES6
rt a from 'path/to/a';
rt b from 'path/to/b';
export default function (x) {
return a(b(x));
};
age: amdtoes6 [options]
tions:
-h, --help output usage information
-d --dir <dirname> Use this option to specify a directory to compile.
-o --out <dirname> If using the --dir option this specifies the output directory.
-i --ignore <glob> If using the --dir options this specifies to exclude eg. libs/**/*
-g --glob [glob] If using the --dir option, optionally specify the glob pattern to match for input files
-b --beautify Run the output through jsbeautify (mainly useful for fixing indentation)
define('my-module', function () {})
define
is not a function literal eg. define(factoryFn)