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:
Bundling custom AdminJS components for serverless deployment
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.moduleis commonjs, use@adminjs/bundler@^2.0.0or before.If you are using ESM (ECMAScript Modules), use
@adminjs/bundler@^3.0.0or after.
Example: Using CommonJS ([email protected])
Install
NPM:
npm install @adminjs/bundler@^2.0.0Yarn:
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
Using Vercel (Recommended Example)
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