A Rollup plugin that converts CommonJS modules to ES modules, designed as an alternative to @rollup/plugin-commonjs. Version 0.8.0 is the latest. It improves on the official plugin by supporting conditional requires (only including the correct branch), detecting require calls in ESM files (e.g., for React Hot Loader), and not stubbing dynamic requires (essential for HMR). It is useful for front-end libraries with best-practice module patterns, but may not work with libraries that reassign module.exports. Named exports require explicit configuration. Suitable for Rollup bundling in development and production.
npm install rollup-plugin-commonjs-alternateVerified import paths — ran on the pinned version, not inferred.
Demonstrates configuring the plugin with namedExports, extensions, and define options in a Rollup config.
Use namedExports option to specify exported names per module.
Avoid dynamic requires; if needed, handle them manually or use a different plugin.
Ensure all CJS modules have 'use strict' or are compliant with strict mode.
If you need .json support, set extensions to ['.js', '.json'] explicitly.
Add @rollup/plugin-node-resolve before the commonjs plugin in the plugins array.
Update to the latest version and add necessary resolve and external plugins.