{"id":14957255,"url":"https://github.com/vercel/rollup-plugin-commonjs","last_synced_at":"2025-10-01T15:31:16.316Z","repository":{"id":65976721,"uuid":"157254222","full_name":"vercel/rollup-plugin-commonjs","owner":"vercel","description":null,"archived":false,"fork":false,"pushed_at":"2018-11-21T10:53:32.000Z","size":456,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-01-15T00:24:47.177Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vercel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-12T17:57:46.000Z","updated_at":"2024-12-11T17:17:17.000Z","dependencies_parsed_at":"2023-02-19T18:45:29.821Z","dependency_job_id":null,"html_url":"https://github.com/vercel/rollup-plugin-commonjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Frollup-plugin-commonjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Frollup-plugin-commonjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Frollup-plugin-commonjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Frollup-plugin-commonjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vercel","download_url":"https://codeload.github.com/vercel/rollup-plugin-commonjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234715684,"owners_count":18875902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:14:26.531Z","updated_at":"2025-10-01T15:31:15.864Z","avatar_url":"https://github.com/vercel.png","language":"JavaScript","readme":"# rollup-plugin-commonjs [![Build Status][travis-img]][travis]\n\n[travis-img]: https://travis-ci.org/rollup/rollup-plugin-commonjs.svg\n[travis]: https://travis-ci.org/rollup/rollup-plugin-commonjs\n\nConvert CommonJS modules to ES6, so they can be included in a Rollup bundle\n\n\n## Installation\n\n```bash\nnpm install --save-dev rollup-plugin-commonjs\n```\n\n\n## Usage\n\nTypically, you would use this plugin alongside [rollup-plugin-node-resolve](https://github.com/rollup/rollup-plugin-node-resolve), so that you could bundle your CommonJS dependencies in `node_modules`.\n\n```js\n// rollup.config.js\nimport commonjs from 'rollup-plugin-commonjs';\nimport nodeResolve from 'rollup-plugin-node-resolve';\n\nexport default {\n  input: 'main.js',\n  output: {\n    file: 'bundle.js',\n    format: 'iife'\n  },\n  plugins: [\n    nodeResolve({\n      jsnext: true,\n      main: true\n    }),\n\n    commonjs({\n      // non-CommonJS modules will be ignored, but you can also\n      // specifically include/exclude files\n      include: 'node_modules/**',  // Default: undefined\n      exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ],  // Default: undefined\n      // these values can also be regular expressions\n      // include: /node_modules/\n\n      // search for files other than .js files (must already\n      // be transpiled by a previous plugin!)\n      extensions: [ '.js', '.coffee' ],  // Default: [ '.js' ]\n\n      // if true then uses of `global` won't be dealt with by this plugin\n      ignoreGlobal: false,  // Default: false\n\n      // if false then skip sourceMap generation for CommonJS modules\n      sourceMap: false,  // Default: true\n\n      // explicitly specify unresolvable named exports\n      // (see below for more details)\n      namedExports: { './module.js': ['foo', 'bar' ] },  // Default: undefined\n\n      // sometimes you have to leave require statements\n      // unconverted. Pass an array containing the IDs\n      // or a `id =\u003e boolean` function. Only use this\n      // option if you know what you're doing!\n      ignore: [ 'conditional-runtime-dependency' ]\n    })\n  ]\n};\n```\n\n### Custom named exports\n\nThis plugin will attempt to create named exports, where appropriate, so you can do this...\n\n```js\n// importer.js\nimport { named } from './exporter.js';\n\n// exporter.js\nmodule.exports = { named: 42 }; // or `exports.named = 42;`\n```\n\n...but that's not always possible:\n\n```js\n// importer.js\nimport { named } from 'my-lib';\n\n// my-lib.js\nvar myLib = exports;\nmyLib.named = 'you can\\'t see me';\n```\n\nIn those cases, you can specify custom named exports:\n\n```js\ncommonjs({\n  namedExports: {\n    // left-hand side can be an absolute path, a path\n    // relative to the current directory, or the name\n    // of a module in node_modules\n    'node_modules/my-lib/index.js': [ 'named' ]\n  }\n})\n```\n\n\n## Strict mode\n\nES modules are *always* parsed in strict mode. That means that certain non-strict constructs (like octal literals) will be treated as syntax errors when Rollup parses modules that use them. Some older CommonJS modules depend on those constructs, and if you depend on them your bundle will blow up. There's basically nothing we can do about that.\n\nLuckily, there is absolutely no good reason *not* to use strict mode for everything — so the solution to this problem is to lobby the authors of those modules to update them.\n\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercel%2Frollup-plugin-commonjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvercel%2Frollup-plugin-commonjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercel%2Frollup-plugin-commonjs/lists"}