{"id":15647990,"url":"https://github.com/egoist/conpack","last_synced_at":"2025-04-30T13:50:40.202Z","repository":{"id":45275159,"uuid":"80019419","full_name":"egoist/conpack","owner":"egoist","description":"Manage webpack config like a boss.","archived":false,"fork":false,"pushed_at":"2021-12-25T14:22:19.000Z","size":200,"stargazers_count":42,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T17:02:32.203Z","etag":null,"topics":["webpack"],"latest_commit_sha":null,"homepage":"","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/egoist.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":"2017-01-25T13:59:28.000Z","updated_at":"2024-05-20T11:09:51.000Z","dependencies_parsed_at":"2022-09-14T05:00:46.380Z","dependency_job_id":null,"html_url":"https://github.com/egoist/conpack","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fconpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fconpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fconpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fconpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/conpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251714827,"owners_count":21631797,"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":["webpack"],"created_at":"2024-10-03T12:22:31.792Z","updated_at":"2025-04-30T13:50:40.170Z","avatar_url":"https://github.com/egoist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# conpack\n\n[![NPM version](https://img.shields.io/npm/v/conpack.svg?style=flat)](https://npmjs.com/package/conpack) [![NPM downloads](https://img.shields.io/npm/dm/conpack.svg?style=flat)](https://npmjs.com/package/conpack) [![CircleCI](https://circleci.com/gh/egoist/conpack/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/conpack/tree/master)  [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe)\n\nManage `rules` and `plugins` in webpack config like a boss.\n\n\u003cdetails\u003e\u003csummary\u003eUse case\u003c/summary\u003e\u003cbr\u003e\n\nImagine friend A writes a package called `create-babel-webpack-config` that adds `babel-loader` to webpack config:\n\n```js\nmodule.exports = () =\u003e {\n  return {\n    module: {\n      rules: [{\n        test: /\\.jsx?$/,\n        use: [{\n          loader: 'babel-loader',\n          options: { presets: ['react-app'] }\n        }]\n      }]\n    }\n  }\n}\n```\n\nThen friend B wants to reuse this package but with some tweaks to use `buble-loader` instead:\n\n```js\n// webpack.config.js\nconst createBabelWebpackConfig = require('create-babel-webpack-config')\n\nconst webpackConfig = createBabelWebpackConfig()\n\nwebpackConfig.module.rules = webpackConfig.module.rules.map(rule =\u003e {\n  if (rule.test.toString() === '/\\\\.jsx?$/') {\n    rule.use[0].loader = 'buble-loader'\n    rule.use[0].options = { target: { node: 6 } }\n  }\n  return rule\n})\n\nmodule.exports = webpackConfig\n```\n\n__THIS IS OBVIOUSLY UGLY!__\n\nFinally friend C shows friend A the power of `conpack`, letting him rewrite `create-babel-webpack-config` to as follows:\n\n```js\nconst Conpack = require('conpack')\n\nmodule.exports = () =\u003e {\n  const conpack = new Conpack()\n  const jsRule = conpack.rules.add('js', {\n    test: /\\.jsx?$/\n  })\n  jsRule.loaders.add('babel', {\n    loader: 'babel-loader',\n    options: {\n      presets: ['react-app']\n    }\n  })\n  return conpack\n}\n```\n\nFor friend B, he can find and modify the rules with confidence:\n\n```js\n// webpack.config.js\nconst createBabelWebpackConfig = require('create-babel-webpack-config')\n\nconst conpack = createBabelWebpackConfig()\n\nconst jsRule = conpack.rules.get('js')\njsRule.loaders.replace('babel', 'buble', {\n  loader: 'buble-loader',\n  options: {\n    target: { node: 6 }\n  }\n})\n\nmodule.exports = conpack.toConfig()\n```\n\u003c/details\u003e\n\n## Install\n\n```bash\nyarn add conpack\n```\n\n\u003cdetails\u003e\u003csummary\u003eExample\u003c/summary\u003e\u003cbr\u003e\n\n```js\n// webpack.config.js\nconst Conpack = require('conpack')\n\nconst conpack = new Conpack()\n\n// Add a rule\nconst jsRule = conpack.rules.add('js', {\n  test: /\\.jsx?$/\n})\njsRule.loaders.add('babel', {\n  loader: 'babel-loader',\n  options: {}\n})\n\n// Change loader later by name\njsRule.loaders.replace('babel', 'buble', {\n  loader: 'buble-loader',\n  options: {}\n})\n\n// Add a plugin\nconpack.plugins.add('uglify', webpack.optimize.UglifyJsPlugin, [\n  {/* options */}\n])\n// Remove a plugin\nconpack.plugins.remove('uglify')\n\nconpack.config = {\n  entry: './src/index.js',\n  output: {\n    path: __dirname,\n    filename: '[name].js'\n  },\n  mode: process.env.NODE_ENV || 'development'\n}\n\nmodule.exports = conpack.toConfig()\n// Alternatively\nmodule.exports = {\n  ...conpack.config,\n  module: {\n    rules: conpack.rules.toArray()\n  },\n  plugins: conpack.plugins.toArray()\n}\n```\n\u003c/details\u003e\n\n## Guide\n\n### General options\n\nFor general options (other than `module.rules` and `plugins`).\n\nNote that following methods support dot-nested path as they're using `lodash.get` `lodash.set` `lodash.unset` under the hood.\n\n#### Getting value\n\n```js\nconpack.get('resolve.modules')\n```\n\n#### Setting value\n\n```js\nconpack.set('resolve.alias.foo$', 'foo-module')\n// { resolve: { alias: { foo$: 'foo-module' } } }\n```\n\n#### Delete value\n\n```js\nconpack.delete('resolve.alias.foo$')\n```\n\n#### Update value\n\n```js\nconpack.update('output.path', currentPath =\u003e currentPath + '/foo')\n```\n\n#### Append value\n\n```js\nconpack.append('entry.client', './foo.js')\n```\n\n#### Prepend value\n\n```js\nconpack.prepend('entry.client', 'webpack/hot/client')\n```\n\n### Rules\n\n#### Add a rule\n\n```js\nconst rule = conpack.rules.add('rule-name', {\n  test: /\\.js$/,\n  // ...options (excluding `use`)\n})\n// =\u003e\n// {\n//   module: {\n//     rules: [\n//       {\n//         test: /\\.js$/,\n//         // ...options\n//       }\n//     ]\n//   }\n// }\n```\n\n#### Prepend a rule\n\n```js\nconpack.rules.prepend('rule-name', options)\n```\n\n#### Get a rule\n\n```js\nconpack.rules.get('rule-name')\n```\n\n#### Update a rule\n\n```js\n// Always got the rule\nconst rule = conpack.rules.get('rule-name')\nrule.update(options =\u003e {\n  options.test = /\\.ext$/\n  return options\n})\n\n// Or update a rule by name directly\nconpack.rules.update('rule-name', options =\u003e newOptions)\n```\n\n#### Delete a rule\n\n```js\nconpack.rules.delete('rule-name')\n```\n\n#### Replace a rule\n\n```js\nconpack.rules.replace('rule-name-to-replace', 'new-rule-name', newOptions)\n```\n\n#### Check if a rule exists\n\n```js\nconpack.rules.has('rule-name')\n```\n\n### Loaders\n\nLoader belong to a rule. \n\nThe API `rule.loaders` is pretty much the same as `conpack.rules`.\n\n### Plugins\n\nThe API `conpack.plugins` is pretty much the same as `conpack.rule`, except for:\n\n- `conpack.plugins.add(name, Plugin, options)`: The second argument is the plugin constructor, the third one is its options as an array.\n- `conpack.plugins.update(name, Plugin, options)`: Update plugin by given `name`.\n- `conpack.plugins.updateOptions(name, options)`: Update plugin options by given `name`.\n\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n\n## Author\n\n**conpack** © [EGOIST](https://github.com/egoist), Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nAuthored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/conpack/contributors)).\n\n\u003e [github.com/egoist](https://github.com/egoist) · GitHub [@EGOIST](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fconpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Fconpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fconpack/lists"}