What I do now is not to call the SwaggerModule.setup() in production mode.
Add production env check and don't init SwaggerModule at all.
@Wizp
How about the swagger annotation in controller and dto?
@arfaWong they shouldn't affect anything at all.
I have this:
if (runEnv === RunEnvironment.Development) {
const sw = await import('@nestjs/swagger')
const swaggerOptions = new sw.DocumentBuilder()
.setTitle('Sample API')
.setVersion('0.1')
.build()
const document = sw.SwaggerModule.createDocument(app, swaggerOptions)
sw.SwaggerModule.setup('docs', app, document)
}
but, it still gets bundled into main.js during ng build api --prod and expects "swagger-ui-express" and "@nestjs/swagger" npm modules to be present in the production docker image (i.e. additional ~5.5MB). Would be nice if there was a way to get rid of it completely in prod environment.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I have this:
but, it still gets bundled into
main.jsduringng build api --prodand expects"swagger-ui-express"and"@nestjs/swagger"npm modules to be present in the production docker image (i.e. additional ~5.5MB). Would be nice if there was a way to get rid of it completely in prod environment.