{"id":13417221,"url":"https://github.com/vite-plugin/vite-plugin-esmodule","last_synced_at":"2025-07-29T03:34:31.360Z","repository":{"id":44564746,"uuid":"503556511","full_name":"vite-plugin/vite-plugin-esmodule","owner":"vite-plugin","description":"Build ES module to CommonJs module for Node.js/Electron","archived":false,"fork":false,"pushed_at":"2024-06-09T09:24:45.000Z","size":149,"stargazers_count":24,"open_issues_count":2,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-07T00:46:39.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/vite-plugin.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-14T23:58:38.000Z","updated_at":"2024-10-06T19:09:17.000Z","dependencies_parsed_at":"2024-01-07T18:04:21.828Z","dependency_job_id":"d017efe8-cb27-4651-9dec-967d5fd4d359","html_url":"https://github.com/vite-plugin/vite-plugin-esmodule","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.021739130434782594","last_synced_commit":"a08ca62e4a69c4e606697de2b852443e7adafee2"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/vite-plugin/vite-plugin-esmodule","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-esmodule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-esmodule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-esmodule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-esmodule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vite-plugin","download_url":"https://codeload.github.com/vite-plugin/vite-plugin-esmodule/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vite-plugin%2Fvite-plugin-esmodule/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267623378,"owners_count":24117178,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-07-30T22:00:34.117Z","updated_at":"2025-07-29T03:34:31.309Z","avatar_url":"https://github.com/vite-plugin.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"readme":"# vite-plugin-esmodule\n\nBuild ES module to CommonJs module for Node.js/Electron\n\n[![NPM version](https://img.shields.io/npm/v/vite-plugin-esmodule.svg)](https://npmjs.org/package/vite-plugin-esmodule)\n[![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-esmodule.svg)](https://npmjs.org/package/vite-plugin-esmodule)\n\n## Why 🤔\n\nWhen using ES modules(e.g.`node-fetch`) in Node.js/Electron projects, we may need to compile them into CommonJs modules to ensure they work correctly.\n\n*在 Node.js/Electron 项目中使用 ES 模块时(e.g. `node-fetch`)，我们可能需要将其编译成 CommonJs 模块，以确保它们能够正常工作*\n\n## Install\n\n```sh\nnpm i -D vite-plugin-esmodule webpack\n```\n\n## Usage\n\nvite.config.js\n\n```js\nimport esmodule from 'vite-plugin-esmodule'\n\nexport default {\n  plugins: [\n    // Take `execa`, `node-fetch` and `file-type` as examples\n    esmodule([\n      'execa',\n      'node-fetch',\n\n      // 🌱 this means that you have explicit specified the entry file\n      { 'file-type': 'file-type/index.js' },\n    ]),\n  ],\n}\n```\n\nexeca.js\n\n```js\nimport {execa} from 'execa';\n\nconst {stdout} = await execa('echo', ['unicorns']);\nconsole.log(stdout);\n//=\u003e 'unicorns'\n```\n\n\u003c!-- [👉 See test](https://github.com/vite-plugin/vite-plugin-esmodule/test) --\u003e\n\n## API \u003csub\u003e\u003csup\u003e(Define)\u003c/sup\u003e\u003c/sub\u003e\n\n`esmodule(modules[, webpack])`\n\n```ts\nimport type { Configuration } from 'webpack'\n\ntype ModuleRecord = string | { [module: string]: string }\n\nfunction esmodule(\n  modules: ModuleRecord[] | ((esmPkgs: string[]) =\u003e ModuleRecord[]),\n  webpack?: ((config: Configuration) =\u003e Configuration | void | Promise\u003cConfiguration | void\u003e),\n): import('vite').Plugin\n```\n\n## How to work\n\nThis plugin just wraps [vite-plugin-optimizer](https://github.com/vite-plugin/vite-plugin-optimizer)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvite-plugin%2Fvite-plugin-esmodule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvite-plugin%2Fvite-plugin-esmodule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvite-plugin%2Fvite-plugin-esmodule/lists"}