npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-vue-builder

v0.9.0

Published

Vue.js server-side and client-side rendering middleware for Koa.js

Downloads

5

Readme

Koa Vue builder

Forked from express-vue-builder

Vue.js server-side rendering middleware for Koa.js (Koa 2)

This package provides production-ready server-side Vue.js application rendering middleware for Koa 2. It creates a new instance of VueRender class (provided by the vue-builder dependency) and sets it on the context object as ctx.vue.

This is an open source package for Vue.js and Koa 2. The source code is available in a github repo where you can also find the issue tracker.

Related Projects

Install

Run the command below to install the package.

$ npm install --save-dev koa-vue-builder vue-builder

Usage

Before we deploy application in production, we need to compile our Vue.js application into a bundle. A bundle is simply a file holding application's source code. Because we would like to render application in browsers as well as on the server, we need to build two bundle files - one targeting browsers, the other targeting the server. Check the attached example on how to build a bundle. Check the documentation of the vue-builder package for details.

Once you've created the bundle file for server-side, you can create a middleware.

const {bundleRenderer} = require('express-vue-builder');

let middleware = bundleRenderer(`./dist/server/bundle.js`); // pass this to app.use() of your Koa application (see example below)

Check the included ./example directory or run the npm run example:start command to start the sample application.

API

bundleRenderer(bundlePath, options)

Server-side rendering middleware for Vue.js application.

| Option | Type | Required | Default | Description |--------|------|----------|---------|------------ | bundlePath | String | Yes | - | Path to server-side application bundle. | options | Object | No | - | Renderer options.

Uses:

Architecture

Works using a piped Transform stream assigned to the context body :)

router.get('/', async (ctx, next) => {
  ctx.type = 'html';
  if (ctx.vue) {
    let stream = ctx.vue.renderToStream();
    let htmlWriter = new HtmlWriterStream();
    ctx.body = stream.pipe(htmlWriter); 
  } else {
    console.log('no .vue object found on ctx. No SSR streaming possible :()');      
  }
  await next();
});

app
  .use(router.routes())
  .use(router.allowedMethods());  

Webpack middleware

Uses Koa specific webpack middleware:

The middlewares are wrapped using convert and compose in order to work with Koa2 async/await promises:

const convert = require('koa-convert');
const compose = convert.compose;

// ...

return compose([
  convert(webpackDevMiddleware(clientCompiler, {
    //...
  }),
  convert(webpackHotMiddleware(clientCompiler, {
    //...
  }
  //...
]);    

TODO: Add more Koa Adapters

Please feel to fork and provide an adapter for Koa 1.x.

Development

Please fork this repo and work from there, then send a PR for each improvement or feature added.

Install/Run

Currently the npm scripts use babel-node to run the various node tasks (using .babelrc config). The code uses async/await which is most suitable for Koa 2 integration. When Node 7.x is out, babel-node might not be (as) necessary!?

Test

npm test

Example app

Build

npm run example:build

Run

npm run example:start

Go to: localhost:3000

License

MIT