{"id":13656792,"url":"https://github.com/bminer/module-concat","last_synced_at":"2025-12-27T01:28:15.040Z","repository":{"id":27487462,"uuid":"30967481","full_name":"bminer/module-concat","owner":"bminer","description":"Fairly lightweight CommonJS module concatenation tool","archived":false,"fork":false,"pushed_at":"2017-11-17T16:32:14.000Z","size":35,"stargazers_count":35,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-22T07:49:53.024Z","etag":null,"topics":["bundler","commonjs","concatenation","javascript","module"],"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/bminer.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":"2015-02-18T13:54:26.000Z","updated_at":"2023-02-02T07:22:39.000Z","dependencies_parsed_at":"2022-08-27T01:41:28.565Z","dependency_job_id":null,"html_url":"https://github.com/bminer/module-concat","commit_stats":null,"previous_names":["bminer/node-module-concat"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fmodule-concat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fmodule-concat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fmodule-concat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fmodule-concat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bminer","download_url":"https://codeload.github.com/bminer/module-concat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250539517,"owners_count":21447328,"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":["bundler","commonjs","concatenation","javascript","module"],"created_at":"2024-08-02T05:00:32.327Z","updated_at":"2025-12-27T01:28:14.990Z","avatar_url":"https://github.com/bminer.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# module-concat\nFairly lightweight CommonJS module concatenation tool\n\n## What is it?\nThis library exposes a single function and stream API that concatenates CommonJS\nmodules within a project.  This can be used to obfuscate an entire project into\na single file.  It can also be used to write client-side JavaScript code where\neach file is written just like a Node.js module.\n\n## Why?\nBecause projects like Webpack and Browserify are cool, but they are a little\nheavy for my taste.  I just wanted something to compile CommonJS modules into a\nsingle JavaScript file.  This project has one dependency:\n[resolve](https://github.com/substack/node-resolve)\n\n## Install\n\n`npm install module-concat`\n\n**Note**: Used to be called `node-module-concat` but has since been renamed.\n\n## Usage\n\n```javascript\nvar modConcat = require(\"module-concat\");\nvar outputFile = \"./project/concatenated.js\";\nmodConcat(\"./project/index.js\", outputFile, function(err, stats) {\n\tif(err) throw err;\n\tconsole.log(stats.files.length + \" were combined into \" + outputFile);\n});\n```\n\n## API\n\n`var modConcat = require(\"module-concat\");`\n\n**`var stream = new modConcat.ModuleConcatStream(entryModulePath [, options])`**\n\nConstructs a [Readable Stream](https://nodejs.org/api/stream.html#stream_class_stream_readable)\nof the concatenated project.\n- `entryModulePath` - the path to the entry point of the project to be\n\tconcatenated.  This might be an `index.js` file, for example.\n- `options` - object to specify any of the following options:\n\t- `outputPath` - the path where the concatenated project file will be\n\t\twritten.  Provide this whenever possible to ensure that instances\n\t\tof `__dirname` and `__filename` are replaced properly.  If\n\t\t`__dirname` and `__filename` are not used in your project or your\n\t\tproject dependencies, it is not necessary to provide this path.  This\n\t\thas no effect when the `browser` option is set.\n\t- `excludeFiles` - An Array of files that should be excluded from the\n\t\tproject even if they were referenced by a `require(...)`.\n\n\t\tNote: These `require` statements should probably be wrapped with a\n\t\tconditional or a try/catch block to prevent uncaught exceptions.\n\t- `excludeNodeModules` - (boolean or Array) Set to `true` if all modules\n\t\tloaded from `node_modules` folders should be excluded from the project.\n\t\tAlternatively, set to an Array of module names to be excluded from the\n\t\tproject.\n\n\t\tFor example, `require(\"foobar\")` will not be replaced if\n\t\t`excludeNodeModules` is set to an Array containing `\"foobar\"` or if\n\t\t`excludeNodeModules` is set to `true`.\n\t- `extensions` - An Array of extensions that will be appended to the\n\t\trequired module path to search for the module in the file system.\n\t\tDefaults to `[\".js\", \".json\"]`.\n\n\t\tFor example, `require(\"./foo\")` will search for:\n\t\t- `./foo`\n\t\t- `./foo.js`\n\t\t- `./foo.json`\n\t\tin that order, relative to the file containing the require statement.\n\n\t\tAnother example, `require(\"./foo.js\")` will search for:\n\t\t- `./foo.js`\n\t\t- `./foo.js.js`\n\t\t- `./foo.js.json`\n\n\t\t**Note**: \".node\" file extensions are considered to be native C/C++\n\t\taddons and are always excluded from the build.\n\t- `compilers` - An Object describing how files with certain file extensions\n\t\tshould be compiled to JavaScript before being included in the project.\n\t\tThe example below will allow module-concat to handle `require`\n\t\tstatements pointing to *.coffee files (i.e. `require(\"./foo.coffee\")`).\n\t\tThese modules are compiled using the coffee-script compiler before\n\t\tthey are included in the project.\n\t\t```javascript\n\t\t{\n\t\t\t// Sample compiler for coffee-script\n\t\t\t\".coffee\": (src, options, path) =\u003e require(\"coffee-script\").compile(src),\n\t\t\t// Sample compiler for Riot.js tags\n\t\t\t\".tag\": (src, options, path) =\u003e\n\t\t\t\t// Note: Variable `riot` needs to be available in the tag module\n\t\t\t\t\"const riot = require('riot');\" +\n\t\t\t\t\t// The compiled tag will contain references to `riot`\n\t\t\t\t\triot.compile(src, {\n\t\t\t\t\t\t// Maybe the *.tag files are Pug templates?\n\t\t\t\t\t\t\"template\": \"pug\",\n\t\t\t\t\t\t// And maybe scoped styles are written in Stylus?\n\t\t\t\t\t\t\"style\": \"stylus\",\n\t\t\t\t\t\t\"compact\": true\n\t\t\t\t\t}, path)\n\t\t}\n\t\t```\n\t\t`options` are passed along to the compiler function, as shown above.\n\t\t`path` is the path of the file being processed.\n\n\t\t**Note**: By default, \".json\" files are prepended with\n\t\t`module.exports = `.  This behavior can be overwritten by explicitly\n\t\tspecifying the \".json\" key in the `compilers` Object.\n\n\t\t**Note**: By default, the file extensions specified in `compilers` are\n\t\tnot added to the `extensions` option, so `require(\"./foo\")` will not\n\t\tfind `./foo.coffee` unless \".coffee\" is explicitly added to `extensions`\n\t\t(see above).\n\t- `browser` - Set to `true` when concatenating this project for the\n\t\tbrowser.  In this case, whenever a required library is loaded from\n\t\t`node_modules`, the `browser` field in the `package.json` file (if\n\t\tfound) is used to determine which file to actually include in the\n\t\tproject.\n\n\t\tmodule-concat provides limited support of the package.json\n\t\t[`browser` field spec](https://github.com/defunctzombie/package-browser-field-spec).\n\t\tMore specifically, it will properly handle the \"basic\" case where\n\t\t`browser` is a string.  When `browser` is an Object, module-concat\n\t\tonly works properly in certain instances.  For example, if the specific\n\t\tfile replaced matches the `main` field, it works fine.  Also, if a\n\t\tspecific file is ignored (i.e. value is set to `false`), its resolved\n\t\tpath is simply added to the `excludeFiles` array.\n\n\t\tUnfortunately, ignoring module names (i.e. not specific files) is not\n\t\tsupported.  Also, replacing module names (or specific files) do not work\n\t\tif the replaced file does not match the `main` field.  This might be\n\t\timproved in the future...\n\t- `allowUnresolvedModules` - Set to `true` to prevent unresolved modules\n\t\tfrom throwing an Error; instead, the `require(...)` expression will not\n\t\tbe replaced, and the unresolved module will be added to\n\t\t`stats.unresolvedModules` (see below).  Defaults to `false` so Errors\n\t\tare thrown for unresolved modules.\n\t- Any [option supported by resolve.sync](https://github.com/substack/node-resolve#resolvesyncid-opts) except\n\t\t`basedir` and `packageFilter`, which can be overwritten.\n\t- Any [option supported by the Readable class](https://nodejs.org/api/stream.html#stream_new_stream_readable_options)\n\n**`stream.getStats()`**\n\nReturns an Object containing statistics about the files included in the\nproject.  This object is available after the 'end' event is fired and there\nis no more data to consume.  Properties include:\n- `files` - An Array of files included in the project\n- `addonsExcluded` - An Array of files excluded from the project because\n\tthey are native C/C++ add-ons.\n- `unresolvedModules` - An Array of modules that could not be included in the\n\tproject because they could not be found.  Each element in the Array is an\n\tObject containing these properties:\n\t- `parent` - the full path of the file containing the require expression\n\t- `module` - the name or path to the module that could not be found\n\n**`modConcat(entryModule, outputPath, [options, cb])`**\n\nHelper function that constructs a new `ModuleConcatStream` (see above) with\nthe following options and pipes the concatenated project to the `outputPath`.\n\n- `entryModule` - the path to the entry point of the project to be\n\tconcatenated.  This might be an `index.js` file, for example.\n- `outputFile` - the path where the concatenated project file will be\n\twritten.\n- `options` - See `options` for `ModuleConcatStream` above.\n- `cb` - Callback of the form `cb(err, stats)`.  If no callback is provided,\n\ta Promise is returned instead, which resolves to the `stats` Object returned\n\tby `stream.getStats()` (see above).\n\n## Known limitations\n- Dynamic `require()` statements don't work\n\t(i.e. `require(\"./\" + variable)`)\n- `require.resolve` calls are not modified\n- `require.cache` statements are not modified\n- Limited support of [package `browser` field spec](https://github.com/defunctzombie/package-browser-field-spec)\n- Won't add any horsepower to your sports car.  :(\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbminer%2Fmodule-concat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbminer%2Fmodule-concat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbminer%2Fmodule-concat/lists"}