Skip to content
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

Set ts config paths from aliases config #2476

Open
1 task done
robert-gruner opened this issue May 28, 2024 · 0 comments
Open
1 task done

Set ts config paths from aliases config #2476

robert-gruner opened this issue May 28, 2024 · 0 comments
Labels
bug Something isn't working p3-minor-issue

Comments

@robert-gruner
Copy link

robert-gruner commented May 28, 2024

Describe the feature

Context

In the past I used Nuxt extensively, now I am also using Nitro by itself to build a standalone server. The Nuxt/Nitro configs are quite similar. The defineNitroConfig takes an input with type NitroConfig which extends NitroOptions. We have the option to set an alias which is described in the docs here. For Nuxt there is a similar option but the docs are different though.

Goal

My expectation would be that the configs work in the same way. I should be able to put aliases in the Nitro config and they are put to the .nitro/types/tsconfig.json under compilerOptions.paths like Nuxt does.

Findings

I found out that I can achieve the desired behaviour by setting both alias and tsConfig.compilerOptions. Example:

export default defineNitroConfig({
  alias: {
    foo: fileURLToPath(new URL('../bar', import.meta.url)),
  },
  typescript: {
      tsConfig: {
        compilerOptions: {
          paths: {
            foo: [fileURLToPath(new URL('../bar', import.meta.url))],
          },
        },
      },
    },
});

At least I hope that this recreates the same behaviour, first tests look good. In Nuxt it is not necessary to also set the typescript.tsConfig part.

Solution

In the perfect world both configs behave the same way. I cannot really assess which implications a change of the Nitro config has. Can we connect alias/typescript settings? For me also an extension/adjustment of the Nitro docs would be ok, since I needed quite some time and digging to figure out how to configure Nitro correctly (assuming the finding above is correct). Anyways I would be open to contribute/suggest a change.

Related

Additional information

  • Would you be willing to help implement this feature?
@pi0 pi0 changed the title Implement Nuxt-like custom TS aliases? Set ts config paths from aliases config May 28, 2024
@pi0 pi0 added bug Something isn't working p3-minor-issue and removed pending triage labels May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p3-minor-issue
Projects
None yet
Development

No branches or pull requests

2 participants