{"id":14989374,"url":"https://github.com/leecade/koa-webpack-middleware","last_synced_at":"2025-04-05T16:09:44.744Z","repository":{"id":52441024,"uuid":"55361444","full_name":"leecade/koa-webpack-middleware","owner":"leecade","description":"webpack dev\u0026hot middleware for koa2","archived":false,"fork":false,"pushed_at":"2021-04-29T03:10:30.000Z","size":738,"stargazers_count":213,"open_issues_count":24,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T15:09:16.279Z","etag":null,"topics":["hmr","koa","koa-webpack-middleware","koa2","webpack","webpack-dev","webpack-dev-middleware"],"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/leecade.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}},"created_at":"2016-04-03T18:17:26.000Z","updated_at":"2024-12-31T13:34:53.000Z","dependencies_parsed_at":"2022-08-18T13:12:43.280Z","dependency_job_id":null,"html_url":"https://github.com/leecade/koa-webpack-middleware","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/leecade%2Fkoa-webpack-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leecade%2Fkoa-webpack-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leecade%2Fkoa-webpack-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leecade%2Fkoa-webpack-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leecade","download_url":"https://codeload.github.com/leecade/koa-webpack-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361693,"owners_count":20926643,"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":["hmr","koa","koa-webpack-middleware","koa2","webpack","webpack-dev","webpack-dev-middleware"],"created_at":"2024-09-24T14:18:15.767Z","updated_at":"2025-04-05T16:09:44.706Z","avatar_url":"https://github.com/leecade.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-webpack-middleware\n\n[![npm version](http://img.shields.io/npm/v/koa-webpack-middleware.svg?style=flat-square)](https://npmjs.org/package/koa-webpack-middleware \"View this project on npm\")\n[![Circle CI](https://circleci.com/gh/leecade/koa-webpack-middleware.svg)](https://circleci.com/gh/leecade/koa-webpack-middleware)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n\n[webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) for [koa2](https://github.com/koajs/koa/tree/v2.x) with [HMR](http://webpack.github.io/docs/hot-module-replacement-with-webpack.html)(hot module replacement) supports.\n\n## Install\n\n```sh\n$ npm i koa-webpack-middleware -D\n```\n\n## Depends\n\nThis middleware designd for koa2 ecosystem, make sure installed the right version:\n\n```sh\nnpm i koa@next -S\n```\n\n## Usage\n\n\u003e See [example/](./example/) for an example of usage.\n\n```js\nimport webpack from 'webpack'\nimport { devMiddleware, hotMiddleware } from 'koa-webpack-middleware'\nimport devConfig from './webpack.config.dev'\nconst compile = webpack(devConfig)\napp.use(devMiddleware(compile, {\n    // display no info to console (only warnings and errors)\n    noInfo: false,\n\n    // display nothing to the console\n    quiet: false,\n\n    // switch into lazy mode\n    // that means no watching, but recompilation on every request\n    lazy: true,\n\n    // watch options (only lazy: false)\n    watchOptions: {\n        aggregateTimeout: 300,\n        poll: true\n    },\n\n    // public path to bind the middleware to\n    // use the same as in webpack\n    publicPath: \"/assets/\",\n\n    // custom headers\n    headers: { \"X-Custom-Header\": \"yes\" },\n\n    // options for formating the statistics\n    stats: {\n        colors: true\n    }\n}))\napp.use(hotMiddleware(compile, {\n  // log: console.log,\n  // path: '/__webpack_hmr',\n  // heartbeat: 10 * 1000\n}))\n```\n\n## HMR configure\n\n1. webpack `plugins` configure\n\n    ```js\n    plugins: [\n        new webpack.optimize.OccurrenceOrderPlugin(),\n        new webpack.HotModuleReplacementPlugin(),\n        new webpack.NoErrorsPlugin()\n    ]\n    ```\n2. webpack `entry` configure\n\n    ```sh\n    $ npm i eventsource-polyfill -D\n    ```\n\n    ```js\n    entry: {\n      'index': [\n        // For old browsers\n        'eventsource-polyfill',\n        'webpack-hot-middleware/client?path=/__webpack_hmr\u0026timeout=20000',\n        'index.js']\n    },\n    ```\n\n3. webpack `loader` configure \n    \n    ```sh\n    $ npm i babel-preset-es2015 babel-preset-stage-0 -D\n    ```\n\n    ```js\n    {\n      test: /\\.js$/,\n      loader: 'babel',\n      query: {\n        'presets': ['es2015', 'stage-0']\n        }\n      },\n      include: './src'\n    }\n    ```\n\n    \u003e HMR for react project\n\n    ```sh\n    $ npm i babel-preset-react babel-preset-react-hmre -D\n    ```\n\n    ```js\n    {\n      test: /\\.jsx?$/,\n      loader: 'babel',\n      query: {\n        'presets': ['es2015', 'stage-0', 'react'],\n        'env': {\n          'development': {\n            'presets': ['react-hmre']\n          }\n        }\n      },\n      include: './src'\n    }\n    ```\n\n4. put the code in your entry file to enable HMR\n\n    \u003e React project do not need\n\n    ```js\n    if (module.hot) {\n      module.hot.accept()\n    }\n    ```\n\nThat's all, you're all set!\n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleecade%2Fkoa-webpack-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleecade%2Fkoa-webpack-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleecade%2Fkoa-webpack-middleware/lists"}