All Projects → leecade → Koa Webpack Middleware

leecade / Koa Webpack Middleware

webpack dev&hot middleware for koa2

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Koa Webpack Middleware

Vue Webpack Config
Koa2、Webpack、Vue、React、Node
Stars: ✭ 151 (-29.77%)
Mutual labels:  webpack, koa, koa2
Koa Mobx React Starter
A straightforward starter for Node javascript web projects. Using Koa, MobX and ReactJS (with universal / isomorphic server rendering)
Stars: ✭ 102 (-52.56%)
Mutual labels:  webpack, koa, koa2
Github Ranking
🔍GitHub不同语言热门项目排行,Vue.js做页面展示
Stars: ✭ 160 (-25.58%)
Mutual labels:  webpack, koa, koa2
Sactive Web
🚀 A dependency injection web framework for Node.js.
Stars: ✭ 143 (-33.49%)
Mutual labels:  koa, koa2
Koa React Isomorphic
Boilerplate for Koa & React
Stars: ✭ 128 (-40.47%)
Mutual labels:  webpack, koa
Fairy
一个能够支持前后端分离并支持中间层同构的完整框架
Stars: ✭ 131 (-39.07%)
Mutual labels:  webpack, koa2
Koa Proxies
a [email protected] proxy middleware
Stars: ✭ 125 (-41.86%)
Mutual labels:  koa, koa2
Kirby Webpack
💪 A Kirby CMS starter-kit with modern frontend tools
Stars: ✭ 150 (-30.23%)
Mutual labels:  webpack, hmr
Breko Hub
Babel React Koa Hot Universal Boilerplate
Stars: ✭ 145 (-32.56%)
Mutual labels:  webpack, koa
Koa Hbs
Handlebars templates for Koa.js
Stars: ✭ 156 (-27.44%)
Mutual labels:  koa, koa2
React Hot Loader Loader
A Webpack Loader that automatically inserts react-hot-loader to your App 👨‍🔬
Stars: ✭ 176 (-18.14%)
Mutual labels:  webpack, hmr
Create Elm App
🍃 Create Elm apps with zero configuration
Stars: ✭ 1,650 (+667.44%)
Mutual labels:  webpack, hmr
Koa Vue Fullstack
A lightweight boilerplate for a universal webapp based on koa, mongodb, node, vue, and webpack
Stars: ✭ 126 (-41.4%)
Mutual labels:  webpack, koa
Dianpinplus
从零开始使用React全家桶开发电商系统
Stars: ✭ 135 (-37.21%)
Mutual labels:  webpack, koa
Bad Ass Salesforce Stack
B.A.S.S. Starter: react / redux / typescript / antd / ts-force / sfdx / webpack / salesforce
Stars: ✭ 126 (-41.4%)
Mutual labels:  webpack, hmr
Template Rwb
A full-featured Webpack setup with hot-reload
Stars: ✭ 165 (-23.26%)
Mutual labels:  webpack, hmr
Blog Service
blog service @nestjs
Stars: ✭ 188 (-12.56%)
Mutual labels:  koa, koa2
Koalerplate
Simple Koa Boilerplate for APIs
Stars: ✭ 118 (-45.12%)
Mutual labels:  koa, koa2
Todolist Frontend Vuejs
Front-end application for Todolist Web application built with Laravel and Vue.js
Stars: ✭ 120 (-44.19%)
Mutual labels:  webpack, hmr
Egg Core
A core Pluggable framework based on koa.
Stars: ✭ 194 (-9.77%)
Mutual labels:  koa, koa2

koa-webpack-middleware

npm version Circle CI js-standard-style

webpack-dev-middleware for koa2 with HMR(hot module replacement) supports.

Install

$ npm i koa-webpack-middleware -D

Depends

This middleware designd for koa2 ecosystem, make sure installed the right version:

npm i [email protected] -S

Usage

See example/ for an example of usage.

import webpack from 'webpack'
import { devMiddleware, hotMiddleware } from 'koa-webpack-middleware'
import devConfig from './webpack.config.dev'
const compile = webpack(devConfig)
app.use(devMiddleware(compile, {
    // display no info to console (only warnings and errors)
    noInfo: false,

    // display nothing to the console
    quiet: false,

    // switch into lazy mode
    // that means no watching, but recompilation on every request
    lazy: true,

    // watch options (only lazy: false)
    watchOptions: {
        aggregateTimeout: 300,
        poll: true
    },

    // public path to bind the middleware to
    // use the same as in webpack
    publicPath: "/assets/",

    // custom headers
    headers: { "X-Custom-Header": "yes" },

    // options for formating the statistics
    stats: {
        colors: true
    }
}))
app.use(hotMiddleware(compile, {
  // log: console.log,
  // path: '/__webpack_hmr',
  // heartbeat: 10 * 1000
}))

HMR configure

  1. webpack plugins configure

    plugins: [
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ]
    
  2. webpack entry configure

    $ npm i eventsource-polyfill -D
    
    entry: {
      'index': [
        // For old browsers
        'eventsource-polyfill',
        'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
        'index.js']
    },
    
  3. webpack loader configure

    $ npm i babel-preset-es2015 babel-preset-stage-0 -D
    
    {
      test: /\.js$/,
      loader: 'babel',
      query: {
        'presets': ['es2015', 'stage-0']
        }
      },
      include: './src'
    }
    

    HMR for react project

    $ npm i babel-preset-react babel-preset-react-hmre -D
    
    {
      test: /\.jsx?$/,
      loader: 'babel',
      query: {
        'presets': ['es2015', 'stage-0', 'react'],
        'env': {
          'development': {
            'presets': ['react-hmre']
          }
        }
      },
      include: './src'
    }
    
  4. put the code in your entry file to enable HMR

    React project do not need

    if (module.hot) {
      module.hot.accept()
    }
    

That's all, you're all set!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].