amd-codemod
v1.0.0
Published
Converts amd modules to es6 modules
Downloads
22
Maintainers
Keywords
Readme
A codemod for jscodeshift that will convert amd modules to es6 ones.
Usage
- npm install -g jscodeshift
- npm install amd-codemod
- jscodeshift -t node_modules/amd-codemod [files]
Example Input -> Output
Module Imports
// input
define([
"some/module",
"some/other/module"
], (
SomeModule,
SomeOtherModule
) => {
});
// output
import SomeModule from "some/module";
import SomeOtherModule from "some/other/module";
Default Return
// input
define([], () => {
return 'some-value';
});
// output
export default 'some-value';
exports
// Input
define(['exports'], (
exports
) => {
exports.someProp = "some-value";
exports.anotherProp = "another-value";
});
// Output
export const someProp = "some-value";
export const anotherProp = "some-value";
export default {someProp, anotherProp};
Inline requires
// Input
const myModule = require("some/module");
// Output
import myModule from "some/module";
Async requires
In the case of webpack you can use require.ensure to load code on demand, with webpack 2 you can do this via System.import.
// Input
require.ensure([], () => {
const myModule = require("some/module");
});
// Output
System.import("some/module").then((someModule) => {
const myModule = someModule;
});