{"id":19451757,"url":"https://github.com/zhengxs2018/vite-plugin-node-externals","last_synced_at":"2026-05-13T08:33:31.113Z","repository":{"id":118133665,"uuid":"601531349","full_name":"zhengxs2018/vite-plugin-node-externals","owner":"zhengxs2018","description":"使 rollup-plugin-node-externals 在 vite 中可用","archived":false,"fork":false,"pushed_at":"2023-02-15T05:43:09.000Z","size":52,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-25T09:34:39.670Z","etag":null,"topics":["externals","library","node-modules","rollup","vite","vite-plugin"],"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/zhengxs2018.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-02-14T09:10:42.000Z","updated_at":"2024-06-06T02:04:27.000Z","dependencies_parsed_at":"2023-07-06T15:31:58.876Z","dependency_job_id":null,"html_url":"https://github.com/zhengxs2018/vite-plugin-node-externals","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/zhengxs2018/vite-plugin-node-externals","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengxs2018%2Fvite-plugin-node-externals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengxs2018%2Fvite-plugin-node-externals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengxs2018%2Fvite-plugin-node-externals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengxs2018%2Fvite-plugin-node-externals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhengxs2018","download_url":"https://codeload.github.com/zhengxs2018/vite-plugin-node-externals/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengxs2018%2Fvite-plugin-node-externals/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32974730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T06:31:55.726Z","status":"ssl_error","status_checked_at":"2026-05-13T06:31:51.336Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["externals","library","node-modules","rollup","vite","vite-plugin"],"created_at":"2024-11-10T16:42:51.692Z","updated_at":"2026-05-13T08:33:31.078Z","avatar_url":"https://github.com/zhengxs2018.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-node-externals\n\n使 [rollup-plugin-node-externals] 在 vite 中生效。\n\n## 安装\n\n```sh\nnpm i vite-plugin-node-externals -D\n```\n\n## 使用\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite'\nimport nodeExternals from 'vite-plugin-node-externals'\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n  ...\n  plugins: [\n    nodeExternals(),\n  ],\n})\n```\n\n## 为什么会有这个？\n\n目前 vite 对于纯 JavaScript 的文件打包已经非常友好，但没有剔除第三方模块的；如果是想要发布一个模块，这是难以接受的。\n\n同时因为 vite 的 [插件顺序](https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering) 导致 [rollup-plugin-node-externals] 模块无法生效。\n\n解决办法其实非常简单，那就是指定 `enforce` 属性，如：\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite'\nimport nodeExternals from 'rollup-plugin-node-externals'\n\nconst externals = {\n  ...nodeExternals(),\n  enforce: 'pre' // 指定为 pre\n}\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n  ...\n  plugins: [\n    externals,\n  ],\n})\n```\n\n那推荐使用这个模块么？不，其实不这么推荐，此模块主要为以后其他不兼容问题，或切换到其他模块时的自用备选方案。\n\n## License\n\nMIT\n\n[rollup-plugin-node-externals]: https://github.com/Septh/rollup-plugin-node-externals\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengxs2018%2Fvite-plugin-node-externals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhengxs2018%2Fvite-plugin-node-externals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengxs2018%2Fvite-plugin-node-externals/lists"}