rollup-plugin-commonjs-named-exports
v1.0.5
Published
Re-export CommonJS named exports using Node.js cjs-module-lexer.
Downloads
514
Maintainers
Readme
rollup-plugin-commonjs-named-exports
Re-export CommonJS named exports using Node.js cjs-module-lexer.
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.