0.7.9 • Published 6 months ago

@brillout/vite-plugin-server-entry v0.7.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

 

What is this?

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

  • Generates the server production entry dist/server/entry.js.
  • Automatically imports it.

Vike and Telefunc automatically use and configure this plugin on your behalf: there is nothing for you to do and you can usually ignore this plugin.

Manual import

Normally the file dist/server/entry.js is automatically imported.

But this automatic importing doesn't work with Yarn PnP and certain Docker configurations, and you'll keep getting the following error:

[@brillout/vite-plugin-server-entry][Wrong Usage] The server production entry is missing.
(Re-)build your app and try again. If you still get this error, then you need to manually
import the server production entry.

The workaround is to manually import dist/server/entry.js in your server code:

// server.js

// Add this import at the begining of your server code
import './path/to/dist/server/entry.js'

// ...
// your server code (Express.js, Hono, Cloudflare Worker, Vercel, ...)
// ...

Make sure to import dist/server/entry.js only in production, see Conditional manual import.

!NOTE The import path may be different:

  • The file extension may be different than .js. (For example dist/server/entry.mjs.)
  • The build directory location may be different than dist/. (For example build/server/entry.js if you set vite.config.js > build.outDir to build.)
- import '../dist/server/entry.js
+ import '../build/server/entry.mjs

!NOTE If you use Vike then make sure that you import dist/server/entry.js before calling renderPage().

!NOTE If you aren't using Yarn PnP nor Docker and you keep getting the The server production entry is missing. error, then file a bug report. Manually importing should only be needed for Yarn PnP and Docker users.

!NOTE Technically, you need to manually import if and only if:

  • your node_modules/ directory is immutable, or
  • you remove/re-install node_modules/ after building your app for production.

If you want to learn more, see How it works.

How it works

!NOTE As a user, you usually don't need to read this. If you have a problem, reading the section Manual import is usually enough.

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

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

The server production entry, which is located at dist/server/entry.js, enables tools such as Vike and Telefunc to consolidate their server production entry into a single file. It loads user files (e.g. Vike's +Page.js user files and/or Telefunc's .telefunc.js user files) built for production.

The auto importer file, which is located at node_modules/@brillout/vite-plugin-server-entry/dist/runtime/autoImporter.js, automatically imports dist/server/entry.js on your behalf, so that you don't have to manually import dist/server/entry.js yourself as shown in the following. That's the only purpose of the auto importer.

// server/index.js (*your* server entry)

// Without the auto importer, you would have to manually import dist/server/entry.js
// yourself, for example like this:
if (process.env.NODE_ENV === 'production') {
  await import('../dist/server/entry.js')
}

See How the auto importer works for more information.

0.7.2

7 months ago

0.5.4

12 months ago

0.7.1

8 months ago

0.5.3

12 months ago

0.7.4

7 months ago

0.5.6

11 months ago

0.7.3

7 months ago

0.5.5

11 months ago

0.5.0

1 year ago

0.7.0

8 months ago

0.5.2

12 months ago

0.5.1

1 year ago

0.7.9

6 months ago

0.7.6

7 months ago

0.5.8

10 months ago

0.7.5

7 months ago

0.5.7

10 months ago

0.7.8

7 months ago

0.7.7

7 months ago

0.6.3

9 months ago

0.6.2

9 months ago

0.6.1

9 months ago

0.6.0

9 months ago

0.4.13

1 year ago

0.4.10

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.11

1 year ago

0.4.12

1 year ago

0.4.7

1 year ago

0.4.6

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago