{"id":21496941,"url":"https://github.com/financial-times/disable-tree-shaking-for-chunk-plugin","last_synced_at":"2025-08-01T15:34:08.984Z","repository":{"id":37866660,"uuid":"224995359","full_name":"Financial-Times/disable-tree-shaking-for-chunk-plugin","owner":"Financial-Times","description":"🌲 A Webpack plugin to disable tree shaking for all JS modules in the specified chunks.","archived":false,"fork":false,"pushed_at":"2024-09-03T12:12:47.000Z","size":34,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":31,"default_branch":"main","last_synced_at":"2024-11-08T22:16:39.051Z","etag":null,"topics":["customer-products","platforms-customer-products"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/disable-tree-shaking-for-chunk-plugin","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/Financial-Times.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-30T10:28:38.000Z","updated_at":"2024-05-21T15:21:13.000Z","dependencies_parsed_at":"2024-06-19T13:23:00.905Z","dependency_job_id":"ae3cedb6-ff33-4a22-8688-26a3564888d1","html_url":"https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin","commit_stats":{"total_commits":34,"total_committers":9,"mean_commits":"3.7777777777777777","dds":0.6470588235294117,"last_synced_commit":"7009d262b2838e034f5bbc1301f1a5d5123b37b2"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Financial-Times%2Fdisable-tree-shaking-for-chunk-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Financial-Times%2Fdisable-tree-shaking-for-chunk-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Financial-Times%2Fdisable-tree-shaking-for-chunk-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Financial-Times%2Fdisable-tree-shaking-for-chunk-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Financial-Times","download_url":"https://codeload.github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226065274,"owners_count":17568183,"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":["customer-products","platforms-customer-products"],"created_at":"2024-11-23T16:19:58.938Z","updated_at":"2024-11-23T16:20:00.281Z","avatar_url":"https://github.com/Financial-Times.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Disable Tree Shaking For Chunk Plugin\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/blob/main/LICENSE) [![Build Status](https://circleci.com/gh/Financial-Times/disable-tree-shaking-for-chunk-plugin.svg)](https://app.circleci.com/pipelines/github/Financial-Times/disable-tree-shaking-for-chunk-plugin) [![npm version](https://img.shields.io/npm/v/disable-tree-shaking-for-chunk-plugin.svg?style=flat)](https://www.npmjs.com/package/disable-tree-shaking-for-chunk-plugin)\n\nThis plugin for [Webpack 5] can disable tree shaking for all modules contained in specified chunks. It is intended to help improve long-term caching and code reuse between project installations and builds.\n\n[Webpack 5]: https://webpack.js.org/\n\n\n## Installation\n\nThis is a [Node.js] module available through the [npm] registry. Node 8 and Webpack 4.38 or higher are required.\n\nInstallation is done using the [npm install] command:\n\n```sh\n$ npm install --save-dev disable-tree-shaking-for-chunk-plugin\n```\n\nOnce installed the plugin can be added to your [Webpack plugins configuration][plugins]:\n\n```js\nconst DisableTreeShakingForChunk = require('disable-tree-shaking-for-chunk-plugin')\n\nmodule.exports = {\n  //...\n  plugins: [\n    new DisableTreeShakingForChunk({\n      test: 'chunk-name'\n    })\n  ]\n}\n```\n\n[Node.js]: https://nodejs.org/\n[npm]: http://npmjs.com/\n[npm install]: https://docs.npmjs.com/getting-started/installing-npm-packages-locally\n[plugins]: https://webpack.js.org/configuration/plugins/\n[optimization]: https://webpack.js.org/configuration/optimization/#optimizationmoduleids\n\n\n## Options\n\n### `test` (string, RegExp, Function, Array, Set)\n\nMatches the chunk name. It may be a string matched with strict equality, a regular expression for more complex string matching, a function which will receive the chunk name as an argument and should return a boolean, or an array or set of strings.\n\n\n## Example\n\nBelow demonstrates part of a Webpack configuration file which sets up code splitting for a project. It has one cache group defined which will create a separate chunk for each package defined in the array.\n\n```js\nconst DisableTreeShakingForChunk = require('disable-tree-shaking-for-chunk-plugin')\n\nconst commonLibraries = ['react', 'redux', 'regenerator-runtime']\n\nmodule.exports = {\n  optimization: {\n    splitChunks: {\n      cacheGroups: {\n        commonLibraries: {\n          test(module) {\n            const packageName = getPackageName(module.context)\n            return packageName ? commonLibraries.includes(packageName) : false\n          },\n          name(module) {\n            return getPackageName(module.context)\n          }\n        }\n      }\n    }\n  },\n  plugins: [\n    new DisableTreeShakingForChunk({\n      test: commonLibraries\n    })\n  ]\n}\n```\n\n\n## Motivation\n\nBy default when running Webpack in production mode it will try to track the properties exported by JavaScript modules and flag when the module is imported and which of those properties is used. It's this clever tracking of \"used exports\" that enables [tree shaking](https://webpack.js.org/guides/tree-shaking/) by \"pruning\" any unused properties. Usually, this is a useful feature as it enables us to ship less code to our users but for cases where we'd like our compiled code to be cached for a long time or be reused by separate applications we need to disable it because how the module may be used over time and by different apps is unknown.\n\n\n## Prior Art\n\nThis plugin is based upon Webpack's internal [`FlagInitialModulesAsUsedPlugin`][flag-plugin] by Tobias Koppers.\n\n[flag-plugin]: https://github.com/webpack/webpack/blob/webpack-4/lib/FlagInitialModulesAsUsedPlugin.js\n\n\n## Development\n\nThis project uses [Prettier] for automatic code formatting and is tested with [Jasmine].\n\n[Prettier]: https://prettier.io/\n[Jasmine]: http://jasmine.github.io/\n\n\n## License\n\nThis package is [MIT] licensed.\n\n[MIT]: https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinancial-times%2Fdisable-tree-shaking-for-chunk-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinancial-times%2Fdisable-tree-shaking-for-chunk-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinancial-times%2Fdisable-tree-shaking-for-chunk-plugin/lists"}