cjs-to-es6

2.0.1 • Public • Published

cjs-to-es6

Maintenance notice: this package is no longer under active maintenance.

CLI to convert JavaScript files from CommonJS to ES6 / ES2015 modules format. The process isn't foolproof, but it can usually get you ~95% of the way there.

This tool uses jscodeshift to run 5to6-codemod and js-codemod under the hood. It attempts to convert require() and module.exports / exports to import and export.

Install

npm i -g cjs-to-es6

Usage

cjs-to-es6 [ --verbose ] files/directories...

All files are modified in-place. You may want to review & rename them to the .mjs extension, if using Node 14 or later. Un-converted files should use the .cjs extension.

Examples:

cjs-to-es6 index.js             # convert a single file
cjs-to-es6 lib/                 # convert all files in a directory & its subdirectories (.js & .cjs)
cjs-to-es6 foo.js bar.js lib/   # convert many files/directories

/cjs-to-es6/

    Package Sidebar

    Install

    npm i cjs-to-es6

    Weekly Downloads

    1,148

    Version

    2.0.1

    License

    Apache-2.0

    Unpacked Size

    16.7 kB

    Total Files

    4

    Last publish

    Collaborators

    • nolanlawson