swagger
swagger copied to clipboard
Optimize swagger-ui-dist loading performance
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [x] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
code:
const start = Date.now();
const config = new DocumentBuilder().build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
console.log(`Swagger loaded in ${Date.now() - start}ms`);
before: Swagger loaded in 101ms
after: Swagger loaded in 26ms
see: https://github.com/swagger-api/swagger-ui/issues/4502
AFAIR swagger-ui-dist suggests to use the getAbsoluteFSPath function for this
getAbsoluteFSPath function is actually a shorthand of require('absolute-path.js'), and the absolute-path.js have test, so we can concern it as stable API.
lgtm