0.3.4 • Published 5 months ago

@brillout/vite-plugin-import-build v0.3.4

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

 

What is this?

@brillout/vite-plugin-import-build automatically loads your server build (i.e. your files at dist/server/).

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.

Manual import

Most of the time @brillout/vite-plugin-import-build is able to automatically import your server build (i.e. your files at dist/server/) there is nothing for you to do.

But @brillout/vite-plugin-import-build 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.

!WARNING 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.

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-import-build does two things:

  • Generates an "import build" file at dist/server/importBuild.cjs.
  • Generates an "auto importer" file at node_modules/@brillout/vite-plugin-import-build/dist/autoImporter.js.

The import build file (dist/server/importBuild.cjs) enables tools, such as Vike and Telefunc, to consolidate their server entry file into a single entry file at dist/server/importBuild.cjs. We recommend having a quick look at the content of dist/server/importBuild.cjs: you'll see that it essentially loads built user files that live inside dist/server/ (e.g. for Telefunc transpiled .telefunc.js user files, and for Vike transpiled +Page.js user files).

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

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

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

See How the auto importer works to learn more.

0.3.4

5 months ago

0.3.3

5 months ago

0.3.2

5 months ago

0.3.0

5 months ago

0.3.1

5 months ago

0.2.22

5 months ago

0.2.21

5 months ago

0.2.20

8 months ago

0.2.19

8 months ago

0.2.18

11 months ago

0.2.17

12 months ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.0

2 years ago

0.0.1

2 years ago