{"id":27998604,"url":"https://github.com/ytiurin/import-export-merger","last_synced_at":"2025-10-27T23:06:03.129Z","repository":{"id":40768441,"uuid":"262039311","full_name":"ytiurin/import-export-merger","owner":"ytiurin","description":"Merge javascript files with imports/exports into one function.","archived":false,"fork":false,"pushed_at":"2023-01-07T18:10:20.000Z","size":1605,"stargazers_count":8,"open_issues_count":26,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T22:54:13.813Z","etag":null,"topics":["build-tool","cli","compiler","export-merger","javascript","javascript-compiler","javascript-modules","module-merger","umd","web"],"latest_commit_sha":null,"homepage":"https://ytiurin.github.io/import-export-merger/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ytiurin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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":"2020-05-07T12:05:31.000Z","updated_at":"2024-02-11T13:28:08.000Z","dependencies_parsed_at":"2023-02-07T20:01:03.436Z","dependency_job_id":null,"html_url":"https://github.com/ytiurin/import-export-merger","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytiurin%2Fimport-export-merger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytiurin%2Fimport-export-merger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytiurin%2Fimport-export-merger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytiurin%2Fimport-export-merger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ytiurin","download_url":"https://codeload.github.com/ytiurin/import-export-merger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253160814,"owners_count":21863625,"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":["build-tool","cli","compiler","export-merger","javascript","javascript-compiler","javascript-modules","module-merger","umd","web"],"created_at":"2025-05-08T22:54:18.501Z","updated_at":"2025-10-27T23:05:58.099Z","avatar_url":"https://github.com/ytiurin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e This tool has a significant design drawback. It doesn't support an import of variables by reference. Still, functions importing works fine.\n\n# import-export-merger\n\n[Try a web tool](https://ytiurin.github.io/import-export-merger/)\n\n_Merge javascript files with imports/exports into one function._ Made to pack code in one file, exculding external dependencies. This is an alternative to code bundling for small libraries.\n\nHaving three files:\n\n```javascript\n/* index.js */\n\nimport { a } from \"./moduleA\";\n\nexport * from \"./moduleB\";\n```\n\n```javascript\n/* moduleA.js */\n\nimport \"external\";\n\nexport const a = 1;\n```\n\n```javascript\n/* moduleB.js */\n\nimport { a } from \"./moduleA\";\n\nconst b = () =\u003e a + 1;\n\nexport default b;\n```\n\nMerging files result to a function:\n\n```javascript\n(function (indexFactory, moduleBFactory, moduleAFactory, external) {\n  var moduleAExports = moduleAFactory(external);\n  var moduleBExports = moduleBFactory(moduleAExports);\n  return indexFactory(moduleAExports, moduleBExports);\n})(\n  function indexFactory(moduleA, moduleB) {\n    var a = moduleA.a;\n\n    return Object.assign({}, moduleB);\n  },\n  function moduleBFactory(moduleA) {\n    var a = moduleA.a;\n    const b = () =\u003e a + 1;\n\n    var $default = b;\n    return { default: $default };\n  },\n  function moduleAFactory(external) {\n    const a = 1;\n    return { a: a };\n  },\n  external\n);\n```\n\nFinal code with UMD declaration:\n\n```javascript\n(function (root, factory) {\n  if (typeof define === \"function\" \u0026\u0026 define.amd) {\n    define([\"external\"], factory);\n  } else if (typeof module === \"object\" \u0026\u0026 module.exports) {\n    module.exports = factory(require(\"external\"));\n  } else {\n    root.myLibrary = factory(root.external);\n  }\n})(typeof self !== \"undefined\" ? self : this, function (external) {\n  return (function (indexFactory, moduleBFactory, moduleAFactory, external) {\n    var moduleAExports = moduleAFactory(external);\n    var moduleBExports = moduleBFactory(moduleAExports);\n    return indexFactory(moduleAExports, moduleBExports);\n  })(\n    function indexFactory(moduleA, moduleB) {\n      var a = moduleA.a;\n\n      return Object.assign({}, moduleB);\n    },\n    function moduleBFactory(moduleA) {\n      var a = moduleA.a;\n      const b = () =\u003e a + 1;\n\n      var $default = b;\n      return { default: $default };\n    },\n    function moduleAFactory(external) {\n      const a = 1;\n      return { a: a };\n    },\n    external\n  );\n});\n```\n\nUMD is enabled by default.\n\n## Install\n\n```bash\nnpm install import-export-merger\n```\n\n## Use as CLI\n\nBasic usage:\n\n```bash\nnpx iemerger src\n```\n\nLooking for `./src/index.js` in current working directory and output result to `\u003cSTDIN\u003e`\n\nOutput to file:\n\n```bash\nnpx iemerger src --output my-library.js\n```\n\nUse CLI in combination with other tools.\n\nFormat output with [prettier](https://prettier.io/ \"Opinionated Code Formatter\"):\n\n```bash\nnpx iemerger src | npx prettier --parser=babel \u003e my-library.js\n```\n\nProcess merged code with with [babel](https://babeljs.io/ \"The compiler for next generation JavaScript\"):\n\n```bash\nnpx iemerger src | npx babel -f my-library.js -o my-library.js\n```\n\nMinify result with [uglifyjs](http://lisperator.net/uglifyjs/ \"JavaScript parser, compressor, minifier written in JS\"):\n\n```bash\nnpx iemerger src | npx uglifyjs -o my-library.js\n```\n\nCombine tools:\n\n```bash\nnpx iemerger src | npx babel -f my-library.js | npx uglifyjs -o my-library.js\n```\n\n## Use with Node\n\nThe library API consists of functions, that are composed with `pipe`.\n\nTo read file and return a function code:\n\n```javascript\nimport { compileModule, makeModule, map, pipe } from \"import-export-merger\";\nimport { readFiles } from \"import-export-merger/fs\";\n\nconst merge = pipe(readFiles, map(fileToModule), compileModule, makeModule);\n\nconst output = merge(\"./src/index.js\");\n```\n\nTo get code from predefined strings:\n\n```javascript\nimport { rawToModule, compileModule, makeModule } from \"import-export-merger\";\n\nconst merge = pipe(rawToModule, compileModule, makeModule);\n\nconst output = merge([\n  { body: 'import { myFunction } from \"./moduleB\";', filepath: \"./moduleA\" },\n  { body: \"export function myFunction() {}\", filepath: \"./moduleB\" },\n]);\n```\n\nAdd UMD wrapper:\n\n```javascript\nimport { makeUMD, pickExternals, supply } from \"import-export-merger\";\n\nconst [makeUMDBody, supplyExternals] = supply(\n  makeUMD,\n  pickExternals,\n  \"myLibrary\"\n);\n\nconst merge = pipe(\n  // ...\n  compileModule,\n  supplyExternals,\n  makeModule,\n  makeUMDBody\n);\n```\n\n## How it works?\n\nAll imports and exports are located with _regular expressions_ and replaced with ES5 compatible code.\n\n## Where can it be used?\n\nIt can be used in an automation flow, when building small NPM modules. It doesn't include external dependencies or non-javascript resources into the build, thus, working faster.\n\n## Dynamic imports\n\nDynamic imports are not supported.\n\n## Comments\n\nAll commentary code is cut out from the source, to prevent bad syntax extraction.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytiurin%2Fimport-export-merger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fytiurin%2Fimport-export-merger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytiurin%2Fimport-export-merger/lists"}