{"id":19778612,"url":"https://github.com/condorheroblog/bundle-import","last_synced_at":"2025-04-30T20:31:21.029Z","repository":{"id":206136196,"uuid":"715083387","full_name":"condorheroblog/bundle-import","owner":"condorheroblog","description":"bundle and `require` a file using the `import-from-string`.","archived":false,"fork":false,"pushed_at":"2024-11-06T14:36:32.000Z","size":92,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-06T14:54:23.507Z","etag":null,"topics":["bundle-import","bundle-require","import-from-string","module-from-string","require-from-string"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/condorheroblog.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-11-06T12:55:16.000Z","updated_at":"2024-11-06T14:36:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"70d6321c-765e-43e0-a3ea-ad306ca09923","html_url":"https://github.com/condorheroblog/bundle-import","commit_stats":{"total_commits":4,"total_committers":2,"mean_commits":2.0,"dds":0.25,"last_synced_commit":"da93a9b5644984e60e105f098e970571952e7f6f"},"previous_names":["condorheroblog/bundle-import"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fbundle-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fbundle-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fbundle-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fbundle-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/condorheroblog","download_url":"https://codeload.github.com/condorheroblog/bundle-import/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224224633,"owners_count":17276427,"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":["bundle-import","bundle-require","import-from-string","module-from-string","require-from-string"],"created_at":"2024-11-12T05:30:08.405Z","updated_at":"2024-11-12T05:30:09.077Z","avatar_url":"https://github.com/condorheroblog.png","language":"TypeScript","readme":"# Bundle-import\n\n[![NPM version](https://img.shields.io/npm/v/bundle-import)](https://www.npmjs.com/package/bundle-import)\n[![Downloads](https://img.shields.io/npm/dw/bundle-import)](https://www.npmjs.com/package/bundle-import)\n[![License](https://img.shields.io/npm/l/bundle-import)](https://github.com/condorheroblog/bundle-import/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/condorheroblog/bundle-import)](https://github.com/condorheroblog/bundle-import/blob/main/packages/bundle-import)\n\nBundle and load a file using the import-from-string.\n\n## Difference from bundle-require\n\nMost of the code of Bundle-import comes from bundle-require. There is no objection to this, but Bundle-import does not generate temporary files when reading module contents, which can avoid conflicts with other tools. For example, the following two issues:\n\n1. [Tmp .mjs file in the current directory breaks other tools](https://github.com/egoist/bundle-require/issues/33)\n2. [vite 运行时，修改mock文件会生成很多个xxx.mjs文件](https://github.com/vbenjs/vite-plugin-mock/issues/98#issuecomment-1782467433)\n\n## Features\n\n- Support ESM and CJS environments\n- Support dynamic import\n- Support `import.meta.url`\n- Support access to global variables\n- No asynchronous IO operations\n- No module cache\n\n## Install\n\n```bash\nnpm install bundle-import\n```\n\n## Usage\n\n### ESM\n\n```mjs\nimport { bundleImport } from \"bundle-import\";\n\nconst { mod: mod1 } = await bundleImport({ filepath: \"./fixtures/index.cjs\", cwd: `${process.cwd()}/playground` });\nconsole.log(mod1);\n\nconst { mod: mod2 } = await bundleImport({ filepath: \"./playground/fixtures/index.mjs\" });\nconsole.log(mod2.default, mod2);\n```\n\n### CJS\n\n```cjs\nconst { bundleImport } = require(\"bundle-import\");\n\nasync function main() {\n\tconst { mod: mod1 } = await bundleImport({ filepath: \"./fixtures/index.cjs\", cwd: `${process.cwd()}/playground` });\n\tconsole.log(mod1);\n\n\tconst { mod: mod2 } = await bundleImport({ filepath: \"./playground/fixtures/index.mjs\" });\n\tconsole.log(mod2.default, mod2);\n}\n\nmain();\n```\n\n## API\n\n### bundleImport(options)\n\n#### options\n\n##### cwd\n\nType: `string`\\\nDefault: `process.cwd()`\n\nProject root directory.\n\n##### filename\n\nType: `string`\\\nRequired: `true`\n\nThe filepath to bundle and require.\n\n##### external\n\nType: `(string | RegExp)[]`\\\nRequired: `[]`\n\nExternal packages.\n\n##### tsconfig\n\nType: `string`\\\nRequired: `tsconfig.json`\n\nA custom tsconfig path to read `paths` option.\n\n##### format\n\nType: `\"cjs\" | \"esm\"`\\\n\nProvide bundle format explicitly to skip the default format inference.\n\n##### esbuildOptions\n\nType: `BuildOptions`\\\nRequired: `false`\n\nesbuild options.\n\n## Appreciation\n\n- [import-from-string](https://github.com/condorheroblog/import-from-string)\n- [bundle-require](https://github.com/egoist/bundle-require)\n- [module-from-string](https://github.com/exuanbo/module-from-string)\n- [require-from-string](https://github.com/floatdrop/require-from-string)\n\n## License\n\n[MIT](https://github.com/condorheroblog/bundle-import/blob/main/LICENSE) License © 2023-Present [Condor Hero](https://github.com/condorheroblog)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcondorheroblog%2Fbundle-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcondorheroblog%2Fbundle-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcondorheroblog%2Fbundle-import/lists"}