-
Notifications
You must be signed in to change notification settings - Fork 9.1k
ES bundle uses CommonJS-style exports. #6678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, is your application not able to tree-shake swagger-ui? As an example, swagger-editor uses and tree-shakes the swagger-ui-es-bundle. |
Hi @tim-lai, When compiling Swagger UI into an Angular app using the Angular CLI, it outputs this warning:
From the link it provides, it states: "It is recommended that you avoid depending on CommonJS modules in your Angular applications. Depending on CommonJS modules can prevent bundlers and minifiers from optimizing your application, which results in larger bundle sizes. Instead, it is recommended that you use ECMAScript modules in your entire application. For more information, see How CommonJS is making your bundles larger." How CommonJS is making your bundles larger: Now I can, of course, ignore or suppress the warning, but it would be better for the ES bundle to utilise ECMAScript exports so that the best optimisation possible can occur, at least IMHO. |
Thanks for the additional info. The ES6 distribution needs to get fixed. |
@linelson as a temporary workaround, I've published a version with a corrected ES bundle. I intend to unpublish as soon as this is issue has been fixed, but should you wish to use it, it's @kensingtontech/swagger-ui. I see that there is a PR in progress @ #6720 so hopefully it won't be too much longer. |
Hello, is there any update to this? My organization has pretty strict compliance with our angular app, and this issue is preventing us from using this package. |
Ping. |
Any updates for this issue? It's been quite sometime. |
I think this is why building swagger breaks for me following an upgrade:
|
Hi everybody, Some aspect of this issue has already been addressed. Here is the full documentation of what each of the fragment represents and what module system is used: #7831. I know the naming is very unfortunate, but we there is a plan to fix it as described in #7831.
Here is the current mapping of the fragments in "exports": {
"./dist/swagger-ui.css": "./dist/swagger-ui.css",
"./dist/oauth2-redirect.html": "./dist/oauth2-redirect.html",
"./dist/swagger-ui-standalone-preset": "./dist/swagger-ui-standalone-preset.js",
".": {
"browser": {
"import": "./dist/swagger-ui-es-bundle-core.js",
"require": "./dist/swagger-ui.js"
},
"node": {
"import": "./dist/swagger-ui-bundle.js",
"require": "./dist/swagger-ui-es-bundle.js"
},
"default": {
"import": "./dist/swagger-ui-bundle.js",
"require": "./dist/swagger-ui-es-bundle.js"
}
}
}, |
It's too few information to help you. I would need to verify that you'll still seeing the issue and provide additional info about your build system or create a POC repo where this can be reproduced. We maintain POC integration repos in https://github.com/swagger-api/swagger-ui/wiki/Seamless-Integration-with-Bundlers-&-Test-Tools Please reopen this issue if you feel it's needed. |
Q&A (please complete the following information)
Content & configuration
Apologies if this isn't considered a bug, but I couldn't find anything clearly explaining this. The ES bundle artefacts still use CommonJ-style exports. I expected that they would be utilising ES6/ES2015-style exports, for use in frameworks like Angular and others that prefer the ES format over CommonJS, for tree-shaking purposes.
swagger-ui-es-bundle.js:
module.exports=function(e){var t={};function...
Should be something like:
export default function(e){var t={};function...
Example Swagger/OpenAPI definition:
N/A
Swagger-UI configuration options:
N/A
Describe the bug you're encountering
To reproduce...
Expected behavior
ES module should use ES-style exports.
Screenshots
N/A
Additional context or thoughts
The text was updated successfully, but these errors were encountered: