Skip to content

Commit

Permalink
docs: how to use swagger-ui with bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbng committed Dec 6, 2023
1 parent 1c1ccbd commit 6926403
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<details>
<summary>Copy files with esbuild</summary>
```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'],
},
}),
],
})
```
</details>
<details>
<summary>Copy files with docker</summary>
```Dockerfile
COPY ./node_modules/@fastify/swagger-ui/static /app/static
```
</details>
#### 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'),
})
```
<a name="license"></a>
## License
Expand Down

0 comments on commit 6926403

Please sign in to comment.