[REQ] [typescript-fetch] Introduce ES2015+ module builds and other improvements
See original GitHub issueIs your feature request related to a problem? Please describe.
Treeshaking the client from the generator doesn’t work all that well. Introducing a module version to the build script and additional package.json options can help with this.
For example, if the generated client produces 4 different API clients, but your app only uses 2, all 4 are still bundled into the project.
Describe the solution you’d like
All suggestions should be non-breaking changes:
- A new
tsconfig.esm.json
file generated alongside the current with the settingmodule: "esnext"
- Build task in the
package.json
to generate as-is and a module version based on the new config (e.g.*.esm.js
versions) package.json
updated to include the following options:
"module": "./dist/index.esm.js",
"sideEffects": false,
I don’t believe any of the code generated has any side effects.
Describe alternatives you’ve considered
using a series of jq
commands post-generation to do it for our needs, but seems like a backwards-compatible change that can benefit all users.
Additional context
Should help webpack (and maybe rollup?) use module imports when the project is able to and enable tree shaking.
I’d be willing to try to implement the changes myself if this is a change OKAYed for the project.
CC @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I go ahead and try to implement it.
Is this the suggested code for the
tsconfig.esm.json
?Open question: Should the
outDir
in the defaulttsconfig.json
changed as well?Change the build command in the
package.json
from:to:
Open question: Are two separate build tasks necessary for backwards compatibility?
And at last adding
module
andsideEffects
to thepackage.json
seems straight forward.If
typescriptThreePlus
isfalse
, shall there be atsconfig.esm.json
for as well? IfsupportsES6
isfalse
, shall there be atsconfig.esm.json
for as well?Should there be an additional property in openapi-codegen-cli, to make this new feature optional?
@Snazzie the changes in java are minimal, see https://github.com/OpenAPITools/openapi-generator/pull/11720/files
you might want to give it a try