@brillout/vite-plugin-import-build

中文文档
0.3.4发布于 2024/01/06MIT近 30 天下载 4.8万
原始使用文档
文档目录3 节
  1. What is this?
  2. Manual import
  3. What it does

 

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.

⇧ TOP ⇧


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.

⇧ 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-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.

⇧ TOP ⇧


版本与发布记录

@brillout/vite-plugin-import-build 共发布 60 个版本,首次发布于 2022/08/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.4latest2024/01/062 年前
0.3.32024/01/062 年前
0.3.22023/12/262 年前
0.3.12023/12/202 年前
0.3.02023/12/202 年前
0.2.22-commit-cb506b02023/12/202 年前

关于 @brillout/vite-plugin-import-build 的常见问题

@brillout/vite-plugin-import-build 是什么?

What is this? - Manual import - What it does

如何安装 @brillout/vite-plugin-import-build?

在项目目录运行 npm install @brillout/vite-plugin-import-build,或使用 pnpm add / yarn add / bun add。

@brillout/vite-plugin-import-build 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/brillout__vite-plugin-import-build 是否存在。

@brillout/vite-plugin-import-build 可以商用吗?

@brillout/vite-plugin-import-build 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brillout/vite-plugin-import-build 的下载量有多少?

根据 npm 官方下载统计,@brillout/vite-plugin-import-build 在 2026/10/09 – 2026/11/07 这 30 天内被下载 48,018 次,日均约 1,601 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brillout/vite-plugin-import-build 还在维护吗?

最新版本 0.3.4 发布于 2024/01/06(2 年前);至今共发布 60 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/08/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。