js-transform-plugin

1.1.10 • Public • Published

English | 简体中文

js-transform-plugin

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

/js-transform-plugin/

    Package Sidebar

    Install

    npm i js-transform-plugin

    Weekly Downloads

    1

    Version

    1.1.10

    License

    MIT

    Unpacked Size

    2.86 MB

    Total Files

    174

    Last publish

    Collaborators

    • trumangao