Skip to content

Instantly share code, notes, and snippets.

@rxw1
Forked from cahnory/middleware.js
Created February 11, 2016 03:27
Show Gist options
  • Save rxw1/1a34f81515a6c89d2a1b to your computer and use it in GitHub Desktop.
Save rxw1/1a34f81515a6c89d2a1b to your computer and use it in GitHub Desktop.

Revisions

  1. @cahnory cahnory created this gist Dec 21, 2015.
    22 changes: 22 additions & 0 deletions middleware.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import connect from 'koa-connect';
    import compose from 'koa-compose';
    import webpack from 'webpack';
    import webpackDev from 'webpack-dev-middleware';
    import webpackHot from 'webpack-hot-middleware';

    export default function (config = {}) {
    let compiler = webpack(config);

    return compose([
    // quick fix
    function * (next) {
    this.status = 200;
    yield next;
    },
    connect(webpackDev(compiler, {
    noInfo: true,
    publicPath: config.output.publicPath
    })),
    connect(webpackHot(compiler))
    ]);
    }