![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@ssrx/vite
Advanced tools
@ssrx/vite
A Vite plugin that improves the DX of developing SSR apps.
It is:
vite dev
, vite build
, etcIt enables:
ssr-manifest.json
file during build that maps client route urls -> assetsassetsForRequest(url: string)
function on the server that returns a list of assets critical to the given
request (along with preload links, etc). You can use this to inject the appropriate asset tags.❗ A small disclaimer... SSRx intentionally does not try to do everything and is intended for a specific audience. If you're looking for a full-fledged framework, SSRx might not be for you. If you are looking to build a modern SSR app with your choice of 3rd party libraries for routing, head management, etc, then SSRx might be right for you.
❗ Remix is transitioning to Vite, so for Vite + React Router projects I now recommend Remix as the best-in-class option.
The SSRx Vite plugin is barebones and (mostly) unopinionated by design, and can be used standalone. See the
bun-react-router
, react-router-simple
,
tanstack-router-simple
, and solid-router-simple
examples.
@ssrx/vite
is mostly unopinionated, but does require 3 things (the file locations are configurable, defaults below):
yarn add @ssrx/vite
yarn add -D vite@5
This file should mount your application in the browser. For React it might look something like this:
// src/entry.client.tsx
import { hydrateRoot } from 'react-dom/client';
import { App } from '~/app.tsx';
hydrateRoot(document, <App />);
A server entry who's default export includes a fetch
function that accepts a
Request and returns a
Response object with your rendered or streamed app.
@ssrx/vite
is focused on supporting the WinterCG standard. Modern node frameworks such asHono
andh3
, as well as alternative runtimes such asbun
,deno
,cloudflare
, and more should all work well with this pattern.
For React, it might look something like this:
// src/server.ts
import { renderToString } from 'react-dom/server';
import { App } from '~/app.tsx';
export default {
fetch(req: Request) {
const html = renderToString(<App />);
return new Response(html, {
headers: {
'Content-Type': 'text/html',
},
});
},
};
Your routes file should export a routes
object. By default @ssrx/vite
expects the routes
object to conform to the
following shape:
type Route = {
// path must adhere to the path-to-regex syntax
path?: string;
children?: Route[];
// If lazy or component.preload point to a dynamic import, that route will be code split
lazy?: () => Promise<any>;
component?: {
preload?: () => Promise<any>;
};
};
react-router
and solid-router
both conform to this shape out of the box. You can provide your own routerAdapter
if
your routes config does not - see plugin-tanstack-router for an example.
Example:
import { ssrx } from '@ssrx/vite/plugin';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
// ... your other plugins
// The plugin, with all of it's defaults.
// You only need to set these options if they deviate from the defaults.
ssrx({
routesFile: 'src/routes.tsx',
clientEntry: 'src/entry.client.tsx',
serverFile: 'src/server.ts',
clientOutDir: 'dist/public',
serverOutDir: 'dist',
runtime: 'node',
routerAdapter: defaultRouterAdapter,
}),
],
});
The ssrx
vite plugin accepts a runtime
option. The available values are:
node
(default)edge
: adjusts Vite to bundle the server output into a single file, and sets resolve conditions that are more
appropriate for ssr / server rendering in popular edge environments.cf-pages
: adjust the output to be suitable for deployment to Cloudflare Pages, including generating sane
_routes.json
and _headers
defaults.Many thanks to these awesome libraries! Please check them out - they provided inspiration as I navigated my first Vite plugin.
FAQs
A Vite plugin that improves the DX of developing SSR apps.
The npm package @ssrx/vite receives a total of 0 weekly downloads. As such, @ssrx/vite popularity was classified as not popular.
We found that @ssrx/vite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.