UI5 serve static middleware

raw JSON →
3.5.0 verified Sat Apr 25 auth: no javascript

ui5-middleware-servestatic v3.5.0 is a community-driven middleware for the UI5 tooling that serves static resources during development. It integrates serve-static to serve files from a root path or an npm package path. Compatible with @ui5/cli@3.0.0+ and specVersion 3.0. Release cadence is moderate, with fixes and features driven by community needs. Key differentiator: simple configuration for custom static resource serving in UI5 projects, supporting environment variables and runtime path resolution.

error Cannot find module 'ui5-middleware-servestatic'
cause Package not installed or not in node_modules.
fix
Run npm install ui5-middleware-servestatic --save-dev.
error ERROR #UI5/00012: Middleware 'ui5-middleware-servestatic' not found
cause UI5 CLI cannot locate the middleware in ui5.yaml dependencies.
fix
Ensure the package is listed in devDependencies and npm install succeeded.
error TypeError: Cannot read properties of undefined (reading 'rootPath')
cause Configuration object missing in ui5.yaml under the middleware entry.
fix
Add configuration: { rootPath: '...' } to your middleware definition.
breaking Major version 3 requires @ui5/cli@3.0.0+ and specVersion 3.0.
fix Upgrade @ui5/cli to version 3 or later and update ui5.yaml specVersion to 3.0.
deprecated The `rootPath` option with a relative path is deprecated; use absolute paths or environment variables instead.
fix Use absolute paths or prefix with env. for environment variables.
gotcha If both `rootPath` and `npmPackagePath` are provided, `rootPath` takes precedence.
fix Provide only one of the two options to avoid confusion.
npm install ui5-middleware-servestatic
yarn add ui5-middleware-servestatic
pnpm add ui5-middleware-servestatic

Shows installation, configuration in ui5.yaml, and programmatic usage of the middleware with Express.

// Install: npm install ui5-middleware-servestatic --save-dev
// In ui5.yaml:
// server:
//   customMiddleware:
//   - name: ui5-middleware-servestatic
//     afterMiddleware: compression
//     mountPath: /resources
//     configuration:
//       rootPath: /path/to/static/resources

// Implementation example:
import express from 'express';
import { middleware } from 'ui5-middleware-servestatic';

const app = express();
app.use('/resources', middleware({
  rootPath: '/path/to/static/resources',
  debug: true
}));

app.listen(3000, () => console.log('Server running on port 3000'));