{"id":13436190,"url":"https://github.com/johnagan/clean-webpack-plugin","last_synced_at":"2025-05-13T21:08:47.135Z","repository":{"id":29913619,"uuid":"33459469","full_name":"johnagan/clean-webpack-plugin","owner":"johnagan","description":"A webpack plugin to remove your build folder(s) before building","archived":false,"fork":false,"pushed_at":"2021-09-01T13:46:08.000Z","size":198,"stargazers_count":1959,"open_issues_count":36,"forks_count":136,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-28T12:15:59.944Z","etag":null,"topics":["clean","javascript","webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/johnagan.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":"2015-04-06T00:03:55.000Z","updated_at":"2025-04-19T17:07:47.000Z","dependencies_parsed_at":"2022-09-10T10:16:04.308Z","dependency_job_id":null,"html_url":"https://github.com/johnagan/clean-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fclean-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fclean-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fclean-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fclean-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnagan","download_url":"https://codeload.github.com/johnagan/clean-webpack-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251311337,"owners_count":21569010,"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":["clean","javascript","webpack","webpack-plugin"],"created_at":"2024-07-31T03:00:45.240Z","updated_at":"2025-04-28T12:16:05.762Z","avatar_url":"https://github.com/johnagan.png","language":"TypeScript","readme":"# Clean plugin for webpack\n\n[![npm][npm-image]][npm-url]\n[![MIT License][mit-license-image]][mit-license-url]\n[![Linux Build Status][circleci-image]][circleci-url]\n[![Windows Build Status][appveyor-image]][appveyor-url]\n[![Coveralls Status][coveralls-image]][coveralls-url]\n\n[npm-url]: https://www.npmjs.com/package/clean-webpack-plugin\n[npm-image]: https://img.shields.io/npm/v/clean-webpack-plugin.svg?label=npm%20version\n[mit-license-url]: LICENSE\n[mit-license-image]: https://camo.githubusercontent.com/d59450139b6d354f15a2252a47b457bb2cc43828/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f7365727665726c6573732e737667\n[circleci-url]: https://circleci.com/gh/johnagan/clean-webpack-plugin/tree/master\n[circleci-image]: https://img.shields.io/circleci/project/github/johnagan/clean-webpack-plugin/master.svg?label=linux%20build\n[appveyor-url]: https://ci.appveyor.com/project/johnagan/clean-webpack-plugin/branch/master\n[appveyor-image]: https://img.shields.io/appveyor/ci/johnagan/clean-webpack-plugin/master.svg?label=windows%20build\n[coveralls-url]: https://codecov.io/gh/johnagan/clean-webpack-plugin/branch/master\n[coveralls-image]: https://img.shields.io/codecov/c/github/johnagan/clean-webpack-plugin/master.svg\n\nA webpack plugin to remove/clean your build folder(s).\n\n\u003e NOTE: Node v10+ and webpack v4+ are supported and tested.\n\n## About\n\nBy default, this plugin will remove all files inside webpack's `output.path` directory, as well as all unused webpack assets after every successful rebuild.\n\n\u003e Coming from `v1`? Please read about [additional v2 information](https://github.com/johnagan/clean-webpack-plugin/issues/106).\n\n## Installation\n\n`npm install --save-dev clean-webpack-plugin`\n\n## Usage\n\n```js\nconst { CleanWebpackPlugin } = require('clean-webpack-plugin');\n\nconst webpackConfig = {\n    plugins: [\n        /**\n         * All files inside webpack's output.path directory will be removed once, but the\n         * directory itself will not be. If using webpack 4+'s default configuration,\n         * everything under \u003cPROJECT_DIR\u003e/dist/ will be removed.\n         * Use cleanOnceBeforeBuildPatterns to override this behavior.\n         *\n         * During rebuilds, all webpack assets that are not used anymore\n         * will be removed automatically.\n         *\n         * See `Options and Defaults` for information\n         */\n        new CleanWebpackPlugin(),\n    ],\n};\n\nmodule.exports = webpackConfig;\n```\n\n## Options and Defaults (Optional)\n\n```js\nnew CleanWebpackPlugin({\n    // Simulate the removal of files\n    //\n    // default: false\n    dry: true,\n\n    // Write Logs to Console\n    // (Always enabled when dry is true)\n    //\n    // default: false\n    verbose: true,\n\n    // Automatically remove all unused webpack assets on rebuild\n    //\n    // default: true\n    cleanStaleWebpackAssets: false,\n\n    // Do not allow removal of current webpack assets\n    //\n    // default: true\n    protectWebpackAssets: false,\n\n    // **WARNING**\n    //\n    // Notes for the below options:\n    //\n    // They are unsafe...so test initially with dry: true.\n    //\n    // Relative to webpack's output.path directory.\n    // If outside of webpack's output.path directory,\n    //    use full path. path.join(process.cwd(), 'build/**/*')\n    //\n    // These options extend del's pattern matching API.\n    // See https://github.com/sindresorhus/del#patterns\n    //    for pattern matching documentation\n\n    // Removes files once prior to Webpack compilation\n    //   Not included in rebuilds (watch mode)\n    //\n    // Use !negative patterns to exclude files\n    //\n    // default: ['**/*']\n    cleanOnceBeforeBuildPatterns: [\n        '**/*',\n        '!static-files*',\n        '!directoryToExclude/**',\n    ],\n    cleanOnceBeforeBuildPatterns: [], // disables cleanOnceBeforeBuildPatterns\n\n    // Removes files after every build (including watch mode) that match this pattern.\n    // Used for files that are not created directly by Webpack.\n    //\n    // Use !negative patterns to exclude files\n    //\n    // default: []\n    cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],\n\n    // Allow clean patterns outside of process.cwd()\n    //\n    // requires dry option to be explicitly set\n    //\n    // default: false\n    dangerouslyAllowCleanPatternsOutsideProject: true,\n});\n```\n\n## Example Webpack Config\n\nThis is a modified version of [WebPack's Plugin documentation](https://webpack.js.org/concepts/plugins/) that includes the Clean Plugin.\n\n```js\nconst { CleanWebpackPlugin } = require('clean-webpack-plugin'); // installed via npm\nconst HtmlWebpackPlugin = require('html-webpack-plugin'); // installed via npm\nconst webpack = require('webpack'); // to access built-in plugins\nconst path = require('path');\n\nmodule.exports = {\n    entry: './path/to/my/entry/file.js',\n    output: {\n        /**\n         * With zero configuration,\n         *   clean-webpack-plugin will remove files inside the directory below\n         */\n        path: path.resolve(process.cwd(), 'dist'),\n    },\n    module: {\n        rules: [\n            {\n                test: /\\.(js|jsx)$/,\n                loader: 'babel-loader',\n            },\n        ],\n    },\n    plugins: [\n        new webpack.ProgressPlugin(),\n        new CleanWebpackPlugin(),\n        new HtmlWebpackPlugin({ template: './src/index.html' }),\n    ],\n};\n```\n","funding_links":[],"categories":["HarmonyOS","TypeScript","Plugins"],"sub_categories":["Windows Manager","Rspack Plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnagan%2Fclean-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnagan%2Fclean-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnagan%2Fclean-webpack-plugin/lists"}