JSPM

@brillout/vite-plugin-server-entry

0.4.10-commit-240f59b
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 57540
  • Score
    100M100P100Q167511F
  • License MIT

Package Exports

  • @brillout/vite-plugin-server-entry/importServerEntry.js
  • @brillout/vite-plugin-server-entry/plugin
  • @brillout/vite-plugin-server-entry/plugin.js
  • @brillout/vite-plugin-server-entry/runtime

Readme

 

What is this?

@brillout/vite-plugin-server-entry generates a server entry dist/server/entry.js and automatically loads it.

Vike and Telefunc automatically add this plugin to your Vite app: there is nothing for you to do and you can usually ignore this plugin.

TOP


Manual import

Most of the time @brillout/vite-plugin-server-entry is able to automatically import the server entry dist/server/entry.js — there is nothing for you to do.

But @brillout/vite-plugin-server-entry doesn't work if you use Yarn PnP and you'll keep getting following error. The workaround is to manually import the server entry.

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

[!WARNING] If you aren't using Yarn PnP and you keep getting this error, then it's a bug that should be fixed — file a bug report.

To manually import the server entry:

// server.js

// Load the server entry, see https://github.com/brillout/vite-plugin-server-entry#manual-import
import './path/to/dist/server/entry.js'

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

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

If the file extension is entry.mjs, import accordingly:

- import './path/to/dist/server/entry.js
+ import './path/to/dist/server/entry.mjs

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

TOP


What it does

[!NOTE] This section is meant for library authors. As a user, you don't need to read this. If you have a problem, read Manual import instead or reach out to maintainers.

@brillout/vite-plugin-server-entry does two things:

  • Generates a "server entry" file at dist/server/entry.js.
  • Generates a "auto importer" file at node_modules/@brillout/vite-plugin-server-entry/dist/importServerEntry/autoImporter.js.

The server entry (dist/server/entry.js) enables tools, such as Vike and Telefunc, to consolidate their entry files into a single file. It enables tools to load built user files (e.g. for Telefunc built .telefunc.js user files, and for Vike built +Page.js user files).

The auto importer file (node_modules/@brillout/vite-plugin-server-entry/dist/importServerEntry/autoImporter.js) automatically imports dist/server/entry.js, so that the user doesn't have to manually import dist/server/entry.js himself as shown in the following. That's the only purpose of the auto importer.

// server/index.js (the user's server file)

// Without the auto importer, the user would have to manually import dist/server/entry.js
// in his server entry file like this:
if (process.env.NODE_ENV === 'production') {
  await import('../dist/server/entry.js')
}

See How the auto importer works to learn more.

TOP