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

@asyarb/vite-plugin-ssr-nojs

v0.1.2

Published

Vite plugin for authoring static HTML with your favorite JS libraries and frameworks.

Downloads

14

Readme

Vite Plugin SSR No JS

A simple Vite plugin to use your preferred JS library as a templating language for static HTML. This plugin will render your provided app as a series of .html files with no JavaScript included.

This plugin's purpose is to provide a modern DX (components, fast hot-reloading, css/asset management, etc.) for authoring basic HTML files, and is not intended for use in large production projects.

Installation

# yarn
yarn add -D @asyarb/vite-plugin-ssr-nojs

# npm
npm i -D @asyarb/vite-plugin-ssr-nojs

Usage

  1. Add the plugin to your Vite config file. See comments for additional information regarding options to pass the plugin.

    // vite.config.ts
    import * as path from 'path'
    import { defineConfig } from 'vite'
    import reactRefresh from '@vitejs/plugin-react-refresh'
    import { ssrNoJsPlugin } from '@asyarb/vite-plugin-ssr-nojs'
    
    export default defineConfig({
      plugins: [
        reactRefresh(),
        ssrNoJsPlugin({
          // An absolute path to a file that renders your app in a server-side
          // context (e.g. ReactDOMServer.renderToStaticMarkup)
          renderModulePath: path.resolve(__dirname, 'src/entry-server.tsx'),
    
          // An absolute path to the output directory of your vite builds.
          viteOutputPath: path.resolve(__dirname, 'dist'),
    
          // A list of routes to statically render. Can be a static array or a
          // function that returns an array of routes.
          routes: ['/', '/about'], // routes: async () => ['/', '/about']
    
          // A static string that will be used as the injection point for your
          // server-rendered HTML. Default: `<!--ssr-html-->`.
          htmlInjectionString: '<!--ssr-html-->',
        }),
      ],
    })
  2. Setup the file specified in renderModulePath. The example below uses React and React Router, but any framework that can render to a string will work.

    // src/entry-server.tsx
    import * as React from 'react'
    import * as ReactDOMServer from 'react-dom/server'
    import { StaticRouter } from 'react-router-dom/server'
    
    import { App } from './App'
    
    // Your renderable module must export a function called `render` that
    // receives the current `route` as a paramter.
    export function render(route: string) {
      return ReactDOMServer.renderToStaticMarkup(
        <StaticRouter location={route}>
          <App />
        </StaticRouter>
      )
    }
    
    // src/App.tsx
    // Imports condensed for brevity.
    export const App = () => {
      return (
        <Routes>
          <Route path="/" element={<HomePage />} />
          <Route path="/about" element={<AboutPage />} />
        </Routes>
      )
    }
  3. Add your htmlInjectionString to your index.html file. This will be replaced with your app's SSR HTML at build time.

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <link rel="icon" type="image/svg+xml" href="/src/assets/favicon.svg" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Vite App</title>
      </head>
      <body>
        <div id="app"><!--ssr-html--></div>
    
        <script type="module" src="/src/main.tsx"></script>
      </body>
    </html>
  4. Run vite build and vite dev as you normally would. On builds, your statically generated HTML files will be available in vite's output directory.

Limitations

TODO, but here's the upshot:

  • JS is completely removed, so any runtime behavior in your app will not run.

License

MIT.