Serverless

AdminJS can be deployed on serverless platforms such as Vercel or AWS Lambda. However, special attention is needed when it comes to bundling custom components and serving static assets.

This guide will walk you through:

  1. Bundling custom AdminJS components for serverless deployment

  2. Serving AdminJS static files in a serverless environment


Bundling AdminJS Components

When deploying AdminJS, any custom React components you add need to be bundled into static files that the client can access. AdminJS does not provide an official CLI for this process, but the @adminjs/bundler package is recommended.

Choosing the Right Bundler Version

  • If your tsconfig.json > compilerOptions.module is commonjs, use @adminjs/bundler@^2.0.0 or before.

  • If you are using ESM (ECMAScript Modules), use @adminjs/bundler@^3.0.0 or after.

Check your module system before installing the bundler to avoid compatibility issues.

Example: Using CommonJS ([email protected])

Install

NPM:

npm install @adminjs/bundler@^2.0.0

Yarn:

Create your component loader:

Create a bundler entry:

Add to your build script (e.g. in package.json):

Running yarn build will output bundled assets in dist/public.


Serving Bundled Files in Serverless

Update your vercel.json to serve both your server (API) and static assets:

This configuration ensures:

  • Your main server is handled by Vercel’s serverless function.

  • Your static assets (custom AdminJS components) are served from /public/.


Loading Bundled Assets in AdminJS

In your AdminJS module configuration, make sure to set assetsCDN to the correct static URL:

Last updated