All Projects → kimjuny → koa-webpack-server

kimjuny / koa-webpack-server

Licence: MIT license
Koa2 webpack all-in-one environment for universal development

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to koa-webpack-server

react-ssr-starter
📚 Featuring Webpack 4, React 17-18, SSR, HMR, prefetching, universal lazy-loading, and more
Stars: ✭ 18 (+28.57%)
Mutual labels:  isomorphic, universal, hmr
server
Serve one or more react apps! - Custom routes, HotReloading, Authenticated Apps/routes, Relay, Webpack..
Stars: ✭ 20 (+42.86%)
Mutual labels:  isomorphic, universal, koa2
Koa React Universal
lightweight React-Koa2 universal boilerplate, only what is essential
Stars: ✭ 112 (+700%)
Mutual labels:  isomorphic, universal, hmr
Universal
Seed project for Angular Universal apps featuring Server-Side Rendering (SSR), Webpack, CLI scaffolding, dev/prod modes, AoT compilation, HMR, SCSS compilation, lazy loading, config, cache, i18n, SEO, and TSLint/codelyzer
Stars: ✭ 669 (+4678.57%)
Mutual labels:  isomorphic, universal, hmr
React Redux Boilerplate
It is a boilerplate of React-Redux as the infrastructure, which helps to setup a Web APP quickly
Stars: ✭ 113 (+707.14%)
Mutual labels:  isomorphic, universal
React Base
atSistemas React/Redux Isomorphic Platform
Stars: ✭ 82 (+485.71%)
Mutual labels:  isomorphic, universal
Arc
React starter kit based on Atomic Design
Stars: ✭ 2,780 (+19757.14%)
Mutual labels:  isomorphic, universal
Universal React Tutorial
📓 How to build universal web apps with React.
Stars: ✭ 136 (+871.43%)
Mutual labels:  isomorphic, universal
Push Starter
React Redux Starter with SSR 🤖
Stars: ✭ 43 (+207.14%)
Mutual labels:  isomorphic, universal
Razzle
✨ Create server-rendered universal JavaScript applications with no configuration
Stars: ✭ 10,547 (+75235.71%)
Mutual labels:  isomorphic, universal
Universal React
A universal react starter, with routing, meta, title, and data features
Stars: ✭ 247 (+1664.29%)
Mutual labels:  isomorphic, universal
Danf
Danf is a Node.js full-stack isomorphic OOP framework allowing to code the same way on both client and server sides. It helps you to make deep architectures and handle asynchronous flows in order to help in producing scalable, maintainable, testable and performant applications.
Stars: ✭ 58 (+314.29%)
Mutual labels:  isomorphic, universal
Universal React Demo
ES6 demo of a simple but scalable React app with react-router, code splitting, server side rendering, and tree shaking.
Stars: ✭ 50 (+257.14%)
Mutual labels:  isomorphic, universal
Jose
Universal "JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK with no dependencies
Stars: ✭ 1,029 (+7250%)
Mutual labels:  isomorphic, universal
Minrouter
a micro middleware router for isomorphic javaScript web apps
Stars: ✭ 159 (+1035.71%)
Mutual labels:  isomorphic, universal
Razzle Material Ui Styled Example
Razzle Material-UI example with Styled Components using Express with compression
Stars: ✭ 117 (+735.71%)
Mutual labels:  isomorphic, universal
React Redux Styled Hot Universal
react boilerplate used best practices and focus on performance
Stars: ✭ 147 (+950%)
Mutual labels:  isomorphic, universal
React Isomorphic Starterkit
Create an isomorphic React app in less than 5 minutes
Stars: ✭ 2,326 (+16514.29%)
Mutual labels:  isomorphic, universal
Beidou
🌌 Isomorphic framework for server-rendered React apps
Stars: ✭ 2,726 (+19371.43%)
Mutual labels:  isomorphic, universal
Nuxt.js
The Intuitive Vue(2) Framework
Stars: ✭ 38,986 (+278371.43%)
Mutual labels:  isomorphic, universal

Koa Webpack Server

Greenkeeper badge Build Status Downloads Code Climate Test Coverage

koa2、webpack、hmr、isomorphic、server-side-render

Koa-Webpack-Server is all-in-one environment for koa2 and webpack2/3 development.

  • Autowire your koa2 app with webpack-dev-middleware.
  • Autowire your koa2 app with webpack-hot-middleware.
  • Autowire your koa2 app with middlewares which are exported from the entry file in your webpack server side config.
  • HMR for client side and server side code, which means you'll never need to restart your node server or refresh your browser to see the changes.

This package is usually used to build a universal/isomorphic SPA applications(React、Vue、Angular) using koa and webpack as setback, making universal/isomorphic web-app development super easy.

For complete examples please refer to:

Noted: This package is still on early stage.

Install

yarn add koa-webpack-server --dev

Usage

server.js

const Koa = require('koa');
const webpack = require('webpack');
const { webpackServer } = require('koa-webpack-server');
const configs = require('../config/webpack.dev.config');
// 👆 array of webpack configurations(client and server)

const app = new Koa();

const options = {
  compilers: webpack(configs),
  dev: {
    noInfo: false,
    quiet: false,
    serverSideRender: true,
  },
};

// wire webpack-dev-middleware、webpack-hot-middleware to app and start webpack-hot-server
webpackServer(app, options).then(({ middlewares }) => {
  // hot-middlewares: you may try making any changes from middlewares,
  // it will automatically rebuild and reload,
  // so that you don't have to reboot your server to see the changes.
  const { logger, render } = middlewares;

  app.use(logger);
  app.use(render);

  app.listen(3000, () => {
    console.log('server started at port 3000');
  });
}).catch((err) => {
});

middlewares.js

// all middlewares are 'AsyncFunction's
const logger = async (ctx, next) => {
  const start = new Date();
  await next();
  const ms = new Date() - start;
  ctx.set('X-Response-Time', `${ms}ms`);
  console.log(`[${ctx.method}][${ms}ms] ${ctx.url}`);
}

export logger;

// you may try making any changes in middlewares, for example,
// change 'Hello World.' to 'Hello World!' and see what's happening.
const render = async (ctx, next) => {
  ctx.body = `
    <!doctype html>
    <html>
      <head><title>koa-webpack-server</title></head>
      <body><div>Hello World.</div></body>
    </html>
  `;
  await next();
}

export render;

For usage detail please refer to basic examples.

API

1. webpackServer: {Function(app: Koa, options: Object):Promise}

options: Object

const options = {
  compilers: Object,  // [Required] webpack compiler
  serverName: String, // webpack server config name, default 'server'
  dev: Object,        // webpack-dev-middleware options
  hot: Object,        // webpack-hot-middleware options
  server: Object,     // hot server options
}

dev: Object

webpack-dev-middleware options.

When serverSideRender is set to true, webpackStats is accessible from ctx.state.webpackStats.

app.use(async (ctx, next) => {
  const assetsByChunkName = ctx.state.webpackStats.toJson().assetsByChunkName;
  // do something with assetsByChunkName
})

For more information please refer to: server-side-rendering.

hot: Object

webpack-hot-middleware options.

server: Object

const server = {
  use: Boolean,      // use hot development middleware? default is true
}

2. findCompiler: {Function(compiler: Compiler || MultiCompiler, name: String): Compiler}

3. findStats: {Function(stats: Stats || MultiStats, name: String): Stats}

License

MIT

Contributing

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].