All Projects → shellscape → Koa Webpack

shellscape / Koa Webpack

Licence: mpl-2.0
Development and Hot Reload Middleware for Koa2

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Koa Webpack

jwt-auth
JSON Web Token Authentication for Laravel and Lumen
Stars: ✭ 46 (-89.28%)
Mutual labels:  middleware, composer
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (-25.64%)
Mutual labels:  middleware, composer
Blog
Front-end tech thoughts and share-ppt
Stars: ✭ 288 (-32.87%)
Mutual labels:  webpack, koa2
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (-84.38%)
Mutual labels:  middleware, koa2
Browser Sync Webpack Plugin
Easily use BrowserSync in your Webpack project.
Stars: ✭ 356 (-17.02%)
Mutual labels:  webpack, webpack2
think-trace
Error trace for ThinkJS 3.x
Stars: ✭ 12 (-97.2%)
Mutual labels:  middleware, koa2
Webpack Cdn Plugin
A webpack plugin that use externals of CDN urls for production and local node_modules for development
Stars: ✭ 306 (-28.67%)
Mutual labels:  webpack, webpack2
Webpack Chain
A chaining API to generate and simplify the modification of Webpack configurations.
Stars: ✭ 2,821 (+557.58%)
Mutual labels:  webpack, webpack2
Google Translate
翻译工具 支持网页翻译和文本翻译
Stars: ✭ 356 (-17.02%)
Mutual labels:  webpack, koa2
Vueniverse
Full stack, user based, PWA, Vue template.
Stars: ✭ 339 (-20.98%)
Mutual labels:  webpack, webpack2
Suddi.github.io
A static single-page application resume-builder developed using React.js and JSON Resume schema (https://suddi.io/)
Stars: ✭ 246 (-42.66%)
Mutual labels:  webpack, webpack2
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (-12.82%)
Mutual labels:  webpack, middleware
Kit
ReactQL starter kit (use the CLI)
Stars: ✭ 232 (-45.92%)
Mutual labels:  webpack, koa2
polix
🚀 Node.js Web Framework
Stars: ✭ 32 (-92.54%)
Mutual labels:  middleware, koa2
Fast Sass Loader
High performance sass loader for webpack
Stars: ✭ 229 (-46.62%)
Mutual labels:  webpack, webpack2
React Dynamic Route Loading Es6
Auto chunking and dynamic loading of routes with React Router and Webpack 2
Stars: ✭ 297 (-30.77%)
Mutual labels:  webpack, webpack2
Webpack Book
From apprentice to master (CC BY-NC-ND)
Stars: ✭ 2,372 (+452.91%)
Mutual labels:  webpack, webpack2
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (-49.88%)
Mutual labels:  webpack, koa2
Markdown Loader
markdown loader for webpack
Stars: ✭ 335 (-21.91%)
Mutual labels:  webpack, webpack2
Awesome Webpack Cn
[印记中文](https://docschina.org/) - webpack 优秀中文文章
Stars: ✭ 3,611 (+741.72%)
Mutual labels:  webpack, webpack2

koa-webpack

tests cover size

Development and Hot Module Reload Middleware for Koa2, in a single middleware module.

This module wraps and composes webpack-dev-middleware and webpack-hot-client into a single middleware module, allowing for quick and concise implementation.

As an added bonus, it'll also use the installed webpack module from your project, and the webpack.config.js file in the root of your project, automagically, should you choose to let it. This negates the need for all of the repetitive setup and config that you get with koa-webpack-middleware.

Install

Using npm:

npm install koa-webpack --save-dev

Requirements

koa-webpack is an evergreen module. 🌲 This module requires an Active LTS Node version (v8.0.0+ or v10.0.0+), and Webpack v4.0.0+.

Usage

const Koa = require('koa');
const koaWebpack = require('koa-webpack');

const app = new Koa();
const options = { .. };
const middleware = await koaWebpack(options);

app.use(middleware);

API

koaWebpack([options])

Returns a Promise which resolves the server middleware containing the following additional properties:

  • close(callback) (Function) - Closes both the instance of webpack-dev-middleware and webpack-hot-client. Accepts a single Function callback parameter that is executed when complete.
  • hotClient (Object) - An instance of webpack-hot-client.
  • devMiddleware (Object) - An instance of webpack-dev-middleware

Options

The middleware accepts an options Object, which can contain options for the webpack-dev-middleware and webpack-hot-client bundled with this module. The following is a property reference for the Object:

compiler

Type: Object
optional

Should you rather that the middleware use an instance of webpack that you've already init'd [with webpack config], you can pass it to the middleware using this option.

Example:

const webpack = require('webpack');
const config = require('./webpack.config.js');
const koaWebpack = require('koa-webpack');

const compiler = webpack(config);
const middleware = await koaWebpack({ compiler });

app.use(middleware);

config

Type: Object

Should you rather that the middleware use an instance of webpack configuration that you've already required/imported, you can pass it to the middleware using this option.

Example:

const koaWebpack = require('koa-webpack');
const config = require('./webpack.config.js');

const middleware = await koaWebpack({ config });

app.use(middleware);

configPath

Type: String

Allows you to specify the absolute path to the Webpack config file to be used.

Example:

const path = require('path');
const koaWebpack = require('koa-webpack');

// The Webpack config file would be at "./client/webpack.config.js".
const middleware = await koaWebpack({
  configPath: path.join(__dirname, 'client', 'webpack.config.js')
});

app.use(middleware);

devMiddleware

Type: Object

The devMiddleware property should contain options for webpack-dev-middleware, a list of which is available at webpack-dev-middleware. Omitting this property will result in webpack-dev-middleware using its default options.

hotClient

Type: Object|Boolean

The hotClient property should contain options for webpack-hot-client, a list of which is available at webpack-hot-client. Omitting this property will result in webpack-hot-client using its default options.

As of v3.0.1 setting this to false will completely disable webpack-hot-client and all automatic Hot Module Replacement functionality.

Using with koa-compress

When using koa-webpack with koa-compress, you may experience issues with saving files and hot module reload. Please review this issue for more information and a workaround.

Server-Side-Rendering

When serverSideRender is set to true in config.devMiddleware, 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 details please refer to: webpack-dev-middleware

Using with html-webpack-plugin

When using with html-webpack-plugin, you can access dev-middleware in-memory filesystem to serve index.html file:

const middleware = await koaWebpack({ config });

app.use(middleware);

app.use(async (ctx) => {
  const filename = path.resolve(webpackConfig.output.path, 'index.html')
  ctx.response.type = 'html'
  ctx.response.body = middleware.devMiddleware.fileSystem.createReadStream(filename)
});

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

Attribution

This module started as a fork of koa-webpack-middleware

License

MPL

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