1.0.2 • Published 6 months ago

rollup-plugin-commonjs-named-exports v1.0.2

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

rollup-plugin-commonjs-named-exports

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Re-export CommonJS named exports using Node.js cjs-module-lexer.

paypal coinbase twitter

Useful to allow import { Fragment, useState } from "react"; (instead of forcing import React from "react";) instance for a bundled React as the source package still re-exports its CJS named exports based on process.env.NODE_ENV:

// react/index.js
if (process.env.NODE_ENV === "production") {
  module.exports = require("./cjs/react.production.min.js");
} else {
  module.exports = require("./cjs/react.development.js");
}
// react/cjs/react.development.js
// ...
exports.Fragment = REACT_FRAGMENT_TYPE;
exports.useReducer = useReducer;
exports.useRef = useRef;
exports.useState = useState;
// ...

Based on esinstall and jspm-rollup.

Installation

npm install rollup-plugin-commonjs-named-exports

Usage

Create a rollup.config.js configuration file and import the plugin:

import commonjs from "@rollup/plugin-commonjs";
import commonjsNamedExports from "rollup-plugin-commonjs-named-exports";

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

Then call rollup either via the CLI or the API.

License

MIT. See license file.