question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ] [typescript-fetch] Introduce ES2015+ module builds and other improvements

See original GitHub issue

Is 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 setting module: "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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sdoeringNewcommented, Feb 12, 2022

I go ahead and try to implement it.


Is this the suggested code for the tsconfig.esm.json?

    {
      "extends": "./tsconfig.json",
      "compilerOptions": {
        "module": "esnext",
        "outDir": "dist/esm"
      }
    }

Open question: Should the outDir in the default tsconfig.json changed as well?


Change the build command in the package.json from:

tsc

to:

tsc -b tsconfig.json tsconfig.esm.json

Open question: Are two separate build tasks necessary for backwards compatibility?


And at last adding module and sideEffects to the package.json seems straight forward.


If typescriptThreePlus is false, shall there be a tsconfig.esm.json for as well? If supportsES6 is false, shall there be a tsconfig.esm.json for as well?


Should there be an additional property in openapi-codegen-cli, to make this new feature optional?

0reactions
macjohnnycommented, Jul 11, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use TypeScript to Build a Node API with Express
This tutorial walks you through building a simple and secure Node application using TypeScript, Express, and Okta.
Read more >
How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >
Documentation - TypeScript 3.6
APIs to Support --build and --incremental​​ TypeScript 3.0 introduced support for referencing other and building them incrementally using the --build flag. ...
Read more >
How to move your project to TypeScript - at your own pace
Learn how you can move your existing JavaScript project, step by step to TypeScript. All at your own pace and as much as...
Read more >
Understanding JavaScript Modules: Bundling & Transpiling
ES2015 modules are the one true future module format for JavaScript. Babel is the ES2015 compiler of choice today. Native loaders are still...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found