{"id":17476900,"url":"https://github.com/bastidest/context-map-webpack-plugin","last_synced_at":"2026-05-02T09:32:10.773Z","repository":{"id":57206511,"uuid":"227232168","full_name":"bastidest/context-map-webpack-plugin","owner":"bastidest","description":"Webpack plugin to map dynamic (thirdparty) dependencies to a static context map.","archived":false,"fork":false,"pushed_at":"2019-12-12T16:04:54.000Z","size":5,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T12:29:11.307Z","etag":null,"topics":["context","import","plugin","require","webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":null,"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/bastidest.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}},"created_at":"2019-12-10T23:04:10.000Z","updated_at":"2019-12-27T15:19:10.000Z","dependencies_parsed_at":"2022-09-04T03:22:54.193Z","dependency_job_id":null,"html_url":"https://github.com/bastidest/context-map-webpack-plugin","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/bastidest%2Fcontext-map-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastidest%2Fcontext-map-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastidest%2Fcontext-map-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastidest%2Fcontext-map-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bastidest","download_url":"https://codeload.github.com/bastidest/context-map-webpack-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246025937,"owners_count":20711575,"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":["context","import","plugin","require","webpack","webpack-plugin"],"created_at":"2024-10-18T19:43:02.842Z","updated_at":"2026-05-02T09:32:10.697Z","avatar_url":"https://github.com/bastidest.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# context-map-webpack-plugin\n\n\u003e Webpack plugin to map dynamic (thirdparty) dependencies to a static context map.\n\n\n## Install\n\n```bash\nnpm install -D context-map-webpack-plugin\n```\n\n## Why do I need it / What does it do?\n\n### The Problem\n\nSome (thirdparty) code requires other files with expressions that\ncannot be resolved by webpack at compile-time. Webpack tries to\ngenerate a regular expression that determines which files to include\nin the webpack bundle. In more complex expressions, webpack is unable\nto determine which files to include, thus an empty context map will be\ncreated.\n\nA dynamic import that cannot be resolved might look like this:\n\n```js\n// ...\nvar FILES = UglifyJS.FILES = [\n    \"../lib/utils.js\",\n    \"../lib/ast.js\",\n    \"../lib/parse.js\",\n    \"../lib/transform.js\",\n    \"../lib/scope.js\",\n    \"../lib/output.js\",\n    \"../lib/compress.js\",\n    \"../lib/sourcemap.js\",\n    \"../lib/mozilla-ast.js\",\n    \"../lib/propmangle.js\",\n    \"./exports.js\",\n].map(function(file){\n    return require.resolve(file);\n});\n// ...\n```\n\nYour webpack build will probably have this `Critical dependency` warning:\n\n```\nWARNING in ./node_modules/uglify-js/tools/node.js 24:11-32\nCritical dependency: the request of a dependency is an expression\n @ ./node_modules/pug-filters/lib/run-filter.js\n @ ./node_modules/pug-filters/index.js\n @ ./node_modules/pug/lib/index.js\n @ ./src/server/PugHandler.ts\n @ ./src/server/Router.ts\n @ ./src/server/index.ts\n @ multi ./src/server/index.ts webpack/hot/poll?1000\n```\n\nThis will result in a bundle output that looks like this:\n\n```\n// ...\n***/ \"./node_modules/uglify-js/tools sync recursive\":\n/*!*******************************************!*\\\n  !*** ./node_modules/uglify-js/tools sync ***!\n  \\*******************************************/\n/*! no static exports found */\n/***/ (function(module, exports) {\n\neval(\"function webpackEmptyContext(req) {\\n\\tvar e = new Error(\\\"Cannot find module '\\\" + req + \\\"'\\\");\\n\\te.code = 'MODULE_NOT_FOUND';\\n\\tthrow e;\\n}\n// ...\n```\n\nThis empty context will lead to runtime errors:\n\n```\nnode ./dist/server/main.js\nundefined:4\n\tthrow e;\n\t^\n\nError: Cannot find module '../lib/utils.js'\n    at Function.webpackEmptyContext [as resolve] (eval at ./node_modules/uglify-js/tools sync recursive (\u003cproject_dir\u003e/dist/server/main.js:5371:1), \u003canonymous\u003e:2:10)\n// ...\n```\n\n### The Solution\n\nCreate a static context map in compile-time in order to include all\nrequired dependencies. You are required to investigate all possible\nruntime values of the required argument where the error originates\nfrom. These values have to be passed as the `staticImports` argument\nin the plugin constructor.\n\n\n### Alternatives\n\nIf you use webpack for the backend, you can exclude the required files\nfrom the webpack bundle and depend on node_mdules by using\n[webpack-node-externals](https://www.npmjs.com/package/webpack-node-externals).\n\n\n## Usage\n\nIn your webpack configuration:\n\n```js\nconst ContextMapPlugin = require('context-map-webpack-plugin');\n\nmodule.exports = {\n  // ...\n  plugins: [\n    new ContextMapPlugin(contextPath, staticImports)\n  ],\n  // ...\n};\n```\n\n## Parameters\n\n### `contextPath`\n\n- Type: `String`\n- Default: `undefined`\n\nSpecify the directory in which to create/overwrite the context map.\n\n\n### `staticImports`\n\n- Type: `Array[String]`\n- Default: `undefined`\n\nStatic imports that will be written to the context map (and bundled with webpack at compile-time).\n\n\n## Example (uglify-js)\n```js\n  // ...\n  plugins: [\n    new ContextMapPlugin('node_modules/uglify-js/tools', [\n      '../lib/utils.js',\n      '../lib/ast.js',\n      '../lib/parse.js',\n      '../lib/transform.js',\n      '../lib/scope.js',\n      '../lib/output.js',\n      '../lib/compress.js',\n      '../lib/sourcemap.js',\n      '../lib/mozilla-ast.js',\n      '../lib/propmangle.js',\n      './exports.js',\n    ])\n  ],\n  // ...\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbastidest%2Fcontext-map-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbastidest%2Fcontext-map-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbastidest%2Fcontext-map-webpack-plugin/lists"}