{"id":13508851,"url":"https://github.com/indutny/webpack-common-shake","last_synced_at":"2025-05-15T17:02:15.151Z","repository":{"id":43901958,"uuid":"95703382","full_name":"indutny/webpack-common-shake","owner":"indutny","description":"CommonJS Tree Shaker plugin for WebPack","archived":false,"fork":false,"pushed_at":"2023-03-01T10:11:31.000Z","size":1102,"stargazers_count":916,"open_issues_count":28,"forks_count":13,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-31T20:11:34.694Z","etag":null,"topics":["commonjs","tree-shaking","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indutny.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,"governance":null}},"created_at":"2017-06-28T19:16:53.000Z","updated_at":"2025-02-12T19:02:21.000Z","dependencies_parsed_at":"2023-02-09T12:45:42.569Z","dependency_job_id":"6dce9afa-96e9-4bfd-a81e-914e7709291a","html_url":"https://github.com/indutny/webpack-common-shake","commit_stats":{"total_commits":88,"total_committers":5,"mean_commits":17.6,"dds":"0.10227272727272729","last_synced_commit":"a082fba7e727da220be3207f2272ef4816a1115f"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indutny%2Fwebpack-common-shake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indutny%2Fwebpack-common-shake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indutny%2Fwebpack-common-shake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indutny%2Fwebpack-common-shake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indutny","download_url":"https://codeload.github.com/indutny/webpack-common-shake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247730069,"owners_count":20986404,"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":["commonjs","tree-shaking","webpack","webpack-plugin"],"created_at":"2024-08-01T02:00:59.380Z","updated_at":"2025-04-07T21:16:11.866Z","avatar_url":"https://github.com/indutny.png","language":"JavaScript","readme":"# CommonJS Tree Shaker plugin for Webpack\n[![NPM version](https://badge.fury.io/js/webpack-common-shake.svg)](http://badge.fury.io/js/webpack-common-shake)\n[![Build Status](https://secure.travis-ci.org/indutny/webpack-common-shake.svg)](http://travis-ci.org/indutny/webpack-common-shake)\n\n![Fancy shaking logo](https://github.com/indutny/webpack-common-shake/blob/master/logo/shake.gif)\n\nPlease file an [issue][0] if anything is broken.\n\nSee [common-shake][1] for abstract bundler-independent implementation.\n\n_NOTE: [webpack][2] version 4 may be needed in order to run this._\n_If you're using webpack 3, please use `webpack-common-shake@1.x`._\n\n_NOTE: Logo is a modified version of [webpack's logo][5]_\n\n## Why?\n\nThere are vast amount of CommonJS modules out there. Thus CommonJS Tree Shaking\nis as important as the ESM module import/export shaking.\n\n## How?\n\nThis plugin removes unused assignments to `exports` properties leaving removal\nof the (presumably) dead code to UglifyJS. If, for example, you had a module:\n\n```js\nexports.used = 1;\nvar tmp = exports.unused = 2;\n```\n\nThis plugin will transform it to:\n\n```js\nexports.used = 1;\nvar tmp = 2;\n```\n\nIt is up to UglifyJS (or some other optimizer) to decide, whether `tmp` is used\nor not and delete it. Luckily it is much simpler for it to do if the uses are\nnot clouded by exporting the values.\n\n## Usage\n\nExample `webpack.config.js`:\n```js\nconst ShakePlugin = require('webpack-common-shake').Plugin;\n\nmodule.exports = [{\n  entry: 'entry.js'\n  output: {\n    path: 'dist',\n    filename: 'output.js'\n  },\n  plugins: [ new ShakePlugin() ]\n}];\n```\n\n## Demonstration\n\nSee [webpack-common-shake-demo][4] for size comparison of output with and\nwithout this plugin.\n\n## Options\n\nPlugin constructor accepts `options` object which may have following properties:\n\n```js\nconst plugin = new ShakePlugin({\n  warnings: {\n    global: true,\n    module: false\n  } /* default */,\n\n  // Invoked on every deleted unused property\n  onExportDelete: (resource, property) =\u003e {},\n\n  // See `Limitations` section for description\n  onModuleBailout: (module, bailouts) =\u003e { ... },\n  onGlobalBailout: (bailouts) =\u003e { ... }\n});\n```\n\n## Limitations\n\nAlthough, generally this module works and helps removing unused code from the\nbundles. There are some limitations that may prevent it from running either\npartially or completely. Some examples are provided below, otherwise please use\ncommon sense (or `onModuleBailout`, `onGlobalBailout` plugin options).\n\nSome local (partial) bailouts:\n\n* Dynamic exports `exports[Math.random()] = ...`\n* Overriding imported vars `var a = require('./a'); a.lib; a = require('./b')`\n* Using `require` in unknown way `console.log(require('./lib'))`\n* Destructuring `require` dynamically `{ [prop]: name } = require('./a')`\n* Dynamic import `var fn = require('./lib')[Math.random()]`\n\nSome global (full) bailouts:\n\n* Dynamic use of require `require(Math.random())`\n\nThis plugin will print some webpack warnings. In any case, bailouts may be\nobtained programmatically too:\n\n```js\nconst plugin = new ShakePlugin({\n  onModuleBailout: (module, bailouts) =\u003e { ... },\n  onGlobalBailout: (bailouts) =\u003e { ... }\n});\n```\n\n## Graph\n\nFor debugging and inspection purposes a graph in [dot][3] format may be\nobtained using `onGraph` option:\n\n```js\nconst plugin = new ShakePlugin({\n  onGraph: (graph) =\u003e { ... }\n});\n```\n\n## LICENSE\n\nThis software is licensed under the MIT License.\n\nCopyright Fedor Indutny, 2017.\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the\nfollowing conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\nNO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\nUSE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[0]: https://github.com/indutny/webpack-common-shake/issues\n[1]: https://github.com/indutny/common-shake\n[2]: https://webpack.github.io/\n[3]: http://www.graphviz.org/content/dot-language\n[4]: https://github.com/indutny/webpack-common-shake-demo\n[5]: https://github.com/webpack/media/issues/12\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findutny%2Fwebpack-common-shake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findutny%2Fwebpack-common-shake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findutny%2Fwebpack-common-shake/lists"}