rollup-plugin-cjs

1.0.0 • Public • Published

rollup-plugin-cjs

Converts CommonJS files to ES modules in a way that's compatible with __esModule files.

Unlike @rollup/plugin-commonjs, this plugin will check for the existence of __esModule at runtime, which should improve compatibility with packages in the wild.

Usage

This plugin should replace @rollup/plugin-commonjs:

import cjs from "rollup-plugin-cjs";

export default {
  input: "src/index.js",
  output: {
    dir: "output",
  },
  plugins: [cjs()],
};

Current limitations

  • Importing using a re-assigned require (e.g. (function(r){r('lib')})(require)) will not work.
  • No tree-shaking for CommonJS.
  • When using import * as lib from 'commonjs-lib the imported values are not live.
  • Dynamic require is not supported.

All of these could be fixed, they are just not implemented at the moment.

Readme

Keywords

none

Package Sidebar

Install

npm i rollup-plugin-cjs

Weekly Downloads

36

Version

1.0.0

License

MIT

Unpacked Size

4.73 kB

Total Files

3

Last publish

Collaborators

  • ntkoopman2