Serverless Build Client Plugin

2.5.0 · maintenance · verified Sun Apr 19

serverless-build-client is a Serverless Framework plugin, currently at version 2.5.0. Its release cadence appears to be maintenance-driven rather than rapid feature development, with the last code commit being five years ago, and v2.5.0 itself being two years old. The plugin is designed to streamline the frontend build process within a Serverless project. Its primary function is to inject environment variables defined in `serverless.yml` (either globally at the provider level or specifically for the plugin) directly into the client-side build environment. This addresses a common challenge in serverless architectures where frontend applications often need dynamic values, such as API endpoints or resource identifiers, that are provisioned by the backend Serverless service. It integrates seamlessly with static site hosting plugins like `serverless-finch` by ensuring the frontend is built with correct environment configurations before deployment. Users define their build command and preferred package manager (npm or yarn), and the plugin handles the environment variable injection and execution of the build script in the specified working directory.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to configure the `serverless-build-client` plugin in `serverless.yml` to inject environment variables into a frontend application build. It shows both global provider environment variables and plugin-specific overrides, using `npm` as the packager and a custom build command from a `frontend` subdirectory. The client build then consumes these injected variables.

/* serverless.yml */
service: my-frontend-app

plugins:
  - serverless-build-client

provider:
  name: aws
  runtime: nodejs18.x
  environment:
    # Global environment variables for the provider
    REACT_APP_GLOBAL_API_URL: https://api.example.com/global

custom:
  buildClient:
    packager: npm # Specify 'npm' as the package manager
    command: run build # Use 'npm run build' as the build command
    cwd: frontend # Specify the subdirectory where the client is located
    verbose: true # Log environment variables during the build
    environment:
      # Plugin-specific environment variables (override global if conflict)
      REACT_APP_BACKEND_ENDPOINT: ${cf:my-backend-service-${sls:stage}.ServiceEndpoint}

# frontend/package.json (example)
// {
//   "name": "my-client-app",
//   "version": "1.0.0",
//   "scripts": {
//     "start": "react-scripts start",
//     "build": "react-scripts build"
//   },
//   "dependencies": {
//     "react": "^18.2.0",
//     "react-dom": "^18.2.0"
//   }
// }

// frontend/src/App.js (example of consuming env vars)
// import React from 'react';
// function App() {
//   return (
//     <div>
//       <h1>Frontend App</h1>
//       <p>Global API URL: {process.env.REACT_APP_GLOBAL_API_URL}</p>
//       <p>Backend Endpoint: {process.env.REACT_APP_BACKEND_ENDPOINT}</p>
//     </div>
//   );
// }
// export default App;

# CLI Command to build the client (run from service root):
serverless client build --stage dev

# Example of deploying a backend service (from backend service root):
# serverless deploy --stage dev

view raw JSON →