JSPM

  • Created
  • Published
  • Downloads 12034
  • Score
    100M100P100Q149896F
  • License MIT

Package Exports

  • @brillout/vite-plugin-import-build
  • @brillout/vite-plugin-import-build/index.js
  • @brillout/vite-plugin-import-build/loadServerBuild
  • @brillout/vite-plugin-import-build/loadServerBuild.js
  • @brillout/vite-plugin-import-build/plugin
  • @brillout/vite-plugin-import-build/plugin.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@brillout/vite-plugin-import-build) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

What is this?

This Vite plugin automatically loads your server build (i.e. your files at dist/server/).

Vite-plugin-ssr and Telefunc automatically add this plugin to your Vite app.

Manual import

Usually this Vite plugin is able to automatically import your server build (i.e. your files at dist/server/) — there is nothing for you to do.

But the plugin doesn't work if you use Yarn PnP and you'll keep getting following error. The workaround is to manually import your server build.

# Yarn PnP users always get this error:
[@brillout/vite-plugin-import-build][Wrong Usage] Cannot find server build. (Re-)build your app
and try again. If you still get this error, then you may need to manually import the server build.

⚠️ If you aren't using Yarn PnP and you keep getting this error, then it's a bug that should be fixed — please open a new issue.

To manually import your server build:

// server.js

// Load server build, see https://github.com/brillout/vite-plugin-import-build#manual-import
import './path/to/dist/server/importBuild.cjs'

// Your server code (Express.js, Vercel Serverless/Edge Function, Cloudflare Worker, ...)
// ...

Make sure to import dist/server/importBuild.cjs only in production. See Conditional manual import if your production and development share the same server entry file.

If you use vite.config.js > build.outDir then replace dist/server/importBuild.cjs with ${build.outDir}/server/importBuild.cjs.

See How it works if you're curious and/or you want to learn more.