rollup-plugin-commonjs-named-exports
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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.

Package Sidebar

Install

npm i rollup-plugin-commonjs-named-exports

Weekly Downloads

18

Version

1.0.2

License

MIT

Unpacked Size

8.88 kB

Total Files

6

Last publish

Collaborators

  • dmnsgn