1.1.10 • Published 10 months ago

js-transform-plugin v1.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

English | 简体中文

An ast plugin for transforming js/ts/jsx/tsx files from commonJS to ESmodule. Here for the examples.

license


Usage

  1. npm install -D js-transform-plugin
  2. Add this script to package.json

    {
      "scripts": {
        "transform": "js-transform"
      }
    }
  3. npm run transform [absolute path]
    • The default value of absolute path is process.cwd().
    • The configuration of ignored files has not been supported. To avoid transforming node_modules dir, you can provide param, like, the absolute path of src dir. Or easier, just delete node_modules dir.
  • Then js/ts/jsx/tsx files in absolute path will be transformed from commonJS to ESmodule recursively.

Examples

// before
const a = require("my-package");

// after
import a from "my-package";
// before
const { a, b, c } = require("my-package");

// after
import { a, b, c } from "my-package";
// before
require("my-package");

// after
import "my-package";
// before
module.exports = { ... }

// after
export { ... }
// or
export default { ... }
// before
module.exports = abc;
module.exports = new Abc();
module.exports = fun(a, b);
module.exports = function(){};
module.exports = () => {};

// after
export default abc;
export default new Abc();
export default fun(a, b);
export default function(){};
export default () => {};
// before
const { b, c } = require("my-package");

// after
import { b, c } from "my-package";
// before
const { d: aliasD } = require("my-package");

// after
import { d as aliasD } from "my-package";

Dependencies

jscodeshift

@babel/core

1.1.9

11 months ago

1.1.10

10 months ago

1.1.8

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago