vite-ssr-vue2
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

Vite logo

vite-ssr-vue2

For building powerful Server Side Rendering APP with Vite ⚡(Next Generation Frontend Tooling)

Features

  • Fast HMR with vite
  • Easy development start
  • Small library size
  • Compatible with Vite's plugin
  • Flexible configuration and full control
  • Support shouldPreload and shouldPrefetch

Documentation

https://webigorkiev.github.io/vite-ssr-vue2/

Installation

Create a normal Vite project for Vue2. (see tests/playground)

Usage

// entry-client.ts
import ssr from "vite-ssr-vue2/client";
import App from "./App.vue";

export default ssr(App);
// entry-server.ts
import ssr from "vite-ssr-vue2/server";
import App from "./App.vue";

export default ssr(App);

There can be only one entry point for the server and for the client. Plugin automatically changes alias for SSR. If for some reason you need separate entry points, then specify the server side in the ssr parameter

Available options for Vite plugin

  • name: plugin name (default: vite-ssr-vue2)
  • ssr: server entry point
Available options for Vite plugin

  • created: ({app, url, isClient, initialState}) - Hook that is called before each request, can be async. May return {router, store, head}
  • mounted: ({app, url, isClient, initialState}) - Hook that is called before each request, can be async. Fire after all internal operations, as router isReady
  • rendered: ({app, url, isClient, initialState}) - Hook that is called before each request, can be async. After ssr rendered or after replace state in client
  • serializer: Custom function for serialization initial state
  • shouldPreload: shouldPreload aka shouldPreload
  • shouldPrefetch: shouldPrefetch aka shouldPrefetch
  • mount: mount options for client side
  • rootProps: root props

Accessing context, res and req objects

In the built-in dev server, context, req, res objects are passing to created hook. In production, you must pass these objects to the rendering function in order to have them available.

({html} = await entry(url, {
    manifest,
    res,
    req,
    context
}));

Redirect

The redirect method add to res object for development, and requires implementation in production.

ClientOnly

Aka vite-ssr, vite-ssr-vue2 exports ClientOnly component that renders its children only in the browser:

import { ClientOnly } from "vite-ssr-vue2"

<div>
  <ClientOnly>
      <!--- your code  --->
  </ClientOnly>
</div>

Production

Run vite build for buildling your app. This will create 2 builds (client and server) that you can import and use from your Node backend.

Package Sidebar

Install

npm i vite-ssr-vue2

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

23 kB

Total Files

13

Last publish

Collaborators

  • webigorkiev