{"id":14976278,"url":"https://github.com/webpack/enhanced-require","last_synced_at":"2025-10-19T11:30:29.804Z","repository":{"id":3773517,"uuid":"4850509","full_name":"webpack/enhanced-require","owner":"webpack","description":"[CURRENTLY UNMAINTAINED] Enhance the require function in node.js with support for loaders which preprocess files. This is a standalone polyfill for features of webpack.","archived":true,"fork":false,"pushed_at":"2015-05-04T06:56:18.000Z","size":442,"stargazers_count":64,"open_issues_count":10,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-29T14:58:03.414Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webpack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-01T13:41:28.000Z","updated_at":"2024-08-15T13:42:01.000Z","dependencies_parsed_at":"2022-09-13T10:11:27.992Z","dependency_job_id":null,"html_url":"https://github.com/webpack/enhanced-require","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-require","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-require/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-require/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-require/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webpack","download_url":"https://codeload.github.com/webpack/enhanced-require/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237116442,"owners_count":19258254,"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":[],"created_at":"2024-09-24T13:53:37.099Z","updated_at":"2025-10-19T11:30:24.549Z","avatar_url":"https://github.com/webpack.png","language":"JavaScript","readme":"# enhanced-require\n\nMore features for node.js require.\n\n* [loader support](https://github.com/sokra/modules-webpack/wiki/Loader-Specification)\n* `require.ensure`\n* AMD `require`, `define` (from require.js)\n* `require.context`\n* [Hot Code Replacement](https://github.com/webpack/enhanced-require/wiki/HCR-Spec)\n* module substitutions for mocking\n\nAsynchron require functions are **really** async. They do not use the sync node.js require, but use a async resolving and async readFile.\n\n## Create a enhanced require function\n\n``` javascript\nvar myRequire = require(\"enhanced-require\")(module, {\n\t// options\n\trecursive: true // enable for all modules recursivly\n\t// This replaces the original require function in loaded modules\n});\n\n// startup your application\nmyRequire(\"./startup\");\n```\n\n## Usage\n\nThan you can use them:\n\n``` javascript\n// use loaders\nvar fileContent = require(\"raw!\"+__filename);\n\n// use loaders automatically\nvar template = require(\"./my-template.jade\");\n\nvar html = template({content: fileContent});\n\n// use require.context\nvar directoryRequire = require.context(\"raw!./subdir\");\nvar txtFile = directoryRequire(\"./aFile.txt\");\n\n// use require.ensure\nrequire.ensure([\"./someFile.js\"], function(require) {\n\tvar someFile = require(\"./someFile.js\");\n});\n\n// use AMD define\nrequire.define([\"./aDep\"], function(aDep) {\n\taDep.run();\n});\n\n// use AMD require\nrequire([\"./bDep\"], function(bDep) {\n\tbDep.doSomething();\n});\n```\n\n## Hot Code Replacement\n\n``` javascript\nrequire(\"enhanced-require\")(module, {\n\trecursive: true, // enable for all modules\n\thot: true, // enable hot code replacement\n\twatch: true // watch for changes\n})(\"./startup\");\n```\n\nFor hot code reloading you need to follow the [hot code reloading spec](https://github.com/webpack/enhanced-require/wiki/HCR-Spec).\n\n## Testing/Mocking\n\n``` javascript\nvar er = require(\"enhanced-require\");\nit(\"should read the config option\", function(done) {\n\tvar subject = er(module, {\n\t\trecursive: true,\n\t\tsubstitutions: {\n\t\t\t// specify the exports of a module directly\n\t\t\t\"../lib/config.json\": {\n\t\t\t\t\"test-option\": { value: 1234 }\n\t\t\t}\n\t\t},\n\t\tsubstitutionFactories: {\n\t\t\t// specify lazy generated exports of a module\n\t\t\t\"../lib/otherConfig.json\": function(require) {\n\t\t\t\t// export the same object as \"config.json\"\n\t\t\t\treturn require(\"../lib/config.json\");\n\t\t\t}\n\t\t}\n\t})(\"../lib/subject\");\n\n\tvar result = subject.getConfigOption(\"test-option\");\n\tshould.exist(result);\n\tresult.should.be.eql({ value: 1234 });\n});\n```\n\n## Options\n\n``` javascript\n{\n\trecursive: false,\n\t// replace require function in required modules with enhanced require method\n\n\tresolve: {\n\t\t// ...\n\t\t// see enhanced-resolve\n\t\t// https://github.com/webpack/enhanced-resolve\n\t},\n\t\n\tsubstitutions: {},\n\tsubstitutionFactories: {},\n\t// See above\n\t// Replace modules with mocks\n\t// keys are resolved and have to exist\n\n\tamd: {},\n\t// The require.amd object\n\n\tenhanced: {},\n\t// The require.enhanced object\n\n\tloader: {},\n\t// additional stuff in the loaderContext\n\n\thot: false,\n\t// enable hot code replacement\n\n\twatch: false,\n\t// Watch for file changes and issue hot replacement\n\n\twatchDelay: 400,\n\t// Time to summarize changes for watching\n}\n```\n\n## Future Plans\n\n* cli tool\n\n## License\n\nCopyright (c) 2012 Tobias Koppers\n\nMIT (http://www.opensource.org/licenses/mit-license.php)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebpack%2Fenhanced-require","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebpack%2Fenhanced-require","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebpack%2Fenhanced-require/lists"}