diff --git a/README.md b/README.md index b33950c..5eee023 100644 --- a/README.md +++ b/README.md @@ -319,6 +319,51 @@ fastify.register('@fastify/swagger-ui', { Note that this behavior is disabled by default in `@fastify/swagger-ui`. +### Bundling + +If you want to bundle Swagger UI with your application, you need to copy the swagger-ui static files to your server yourself and set the `baseDir` option to point to your folder. + +
+Copy files with esbuild + +```js +import { build } from 'esbuild' +import { copy } from 'esbuild-plugin-copy' + +await build({ + // ... + plugins: [ + copy({ + resolveFrom: 'cwd', + assets: { + from: ['node_modules/@fastify/swagger-ui/static/*'], + to: ['dist/static'], + }, + }), + ], +}) +``` + +
+ +
+Copy files with docker + +```Dockerfile +COPY ./node_modules/@fastify/swagger-ui/static /app/static +``` + +
+ +#### Configure Swagger UI to use a custom baseDir +Set the `baseDir` option to point to your folder. + +```js +await fastify.register(require('@fastify/swagger-ui'), { + baseDir: isDev ? undefined : path.resolve('static'), +}) +``` + ## License