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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-ssr-vue3

v0.1.4

Published

vite ssr plugin for vue3

Readme

Vite-SSR-Vue3

version

Vite plugin for vue Server-Side Rendering, Used express to create a server.

Usage

Install

# npm
npm install -D vite-ssr-vue3 vue-router

# yarn
yarn add -D vite-ssr-vue3 vue-router

# pnpm
pnpm add -D vite-ssr-vue3 vue-router

# pnpm workspaces
pnpm add -D vite-ssr-vue3 vue-router -F <Repo Name> 

Modify package.json scripts to:

{
  "scripts": {
-   "dev": "vite --port 3333",
+   "dev": "vite-ssr --port 3333",
-   "build": "vite build",
+   "build": "vite-ssr build",
+   "serve": "vite-ssr --mode production"
  },
}
// src/main.ts
import { ViteSSR } from 'vite-ssr-vue3'
import routes from './routes'
import App from './App.vue'

// Export `createApp` function is required by vite-ssr
export const createApp = ViteSSR(App, { routes }, (context) => {
  // if (import.meta.env.SSR) {
  //   // Running in server
  // } else {
  //   // Running in browser
  // }
})

Initial State

// src/main.ts
import { ViteSSR } from 'vite-ssr-vue3'
import routes from './routes'
import App from './App.vue'

export const createApp = ViteSSR(App, { routes }, (context) => {
  const { app, initialState } = context

  // Use pinia to store your data
  const pinia = createPinia()

  if (import.meta.env.SSR)
    initialState.pinia = pinia.state.value
  else
    pinia.state.value = initialState.pinia

})

Data Fetching

import { useFetch } from 'vite-ssr-vue3'

const counts = await useFetch('counts', () => Promise.resolve([1, 2, 3]))

Full Control Build

vite-ssr build command default equals build client and server, so you can customize your build process.

{
  "scripts": {
+   "build": "vite-ssr build",
-   "build:client": "vite build --ssrManifest --outDir dist/client",
-   "build:server": "vite build --ssr src/main.ts --outDir dist/server",
  },
}

vite-ssr support separate options for client and server building, Configure them for separate builds

import { defineConfig } from 'vite'

export default defineConfig({
  ssrOptions: {
    // Client build options
    clientConfig: {},
    // Server build options
    serverConfig: {},
  },
})

Compiled with vite-ssr build, there are three ways to start the server:

  1. Run vite-ssr --mode production

  2. Use vite-ssr built-in express server, then run node ./bin/www

    // ./bin/www.js
    const { startExpressServer: startServer } = require('vite-ssr-vue3/server')
    const { createApp } = require('../dist/server/main.cjs')
    
    startServer({ createApp })
  3. Customize server

    vite-ssr-vue3/server export a function createRender to allows you create a render function.

    // ./src/express.js
    // @ts-check
    const path = require('path')
    const express = require('express')
    const { createRender } = require('vite-ssr-vue3/server')
    
    async function createServer() {
      const out = path.join(__dirname, '../dist')
      const resolve = p => path.resolve(out, p)
      const app = express()
      app.use(express.static(resolve('./client'), {
        index: false,
        maxAge: '1y',
      }))
    
      const render = await createRender({ isProd: true, root: __dirname, outDir: '../dist' })
      const { createApp } = require(resolve('./server/main.cjs'))
    
      app.use('*', async(req, res) => {
        try {
          const url = req.originalUrl
    
          if (req.method !== 'GET' || url === '/sw.js' || url === '/favicon.ico')
            return
    
          const context = await createApp(false)
          let html = await render(url, { context })
    
          html += '\n<!-- From customize server -->'
    
          res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
        }
        catch (error) {
          -console.error(error)
          res.status(500).end(error.stack)
        }
      })
    
      return { server: app }
    }
    
    createServer().then(({ server }) =>
      server.listen(3000, () => {
        // eslint-disable-next-line no-console
        console.info('http://localhost:3000')
      }),
    )

I three ways, we need to strongly depend on the server, although we can use ssr.noExternal to package dependencies, but the server cannot be packaged in, you must install server package npm install express

we can modify the server building entry file to avoid this, create a new file to wrapper your server instance(vite-ssr will not works), configure ssr.noExternal: /./ to package all dependencies. if you want to runing anywhere, this is recommended.

// src/server.ts
import { startExpressServer as startServer } from 'vite-ssr-vue3/server'
import { createApp } from './main'

startServer({ createApp, root: __dirname, outDir: '..' })
// vite.config.noexternal.ts
import type { UserConfig } from 'vite'
import { defineConfig } from 'vite'

export default defineConfig({
  ssrOptions: {
    serverConfig: {
      build: {
        ssr: './src/server',
      },
      ssr: {
        noExternal: /./,
      },
    },
  },
} as UserConfig)

then run vite-ssr build:noexternal, wait for a while, now you can run node dist/server/server.cjs (Required right path) to start the server anywhere.

Thanks

Lots of references to the following repos.

License

MIT