Subwaytime / vite-aliases

Alias auto generation for Vite
https://www.npmjs.com/package/vite-aliases
MIT License
213 stars 13 forks source link

Don't forget about baseURL #39

Closed seivan closed 2 years ago

seivan commented 2 years ago

In my case, I don't use path aliases. I just use "baseUrl": "src",

So I can import from root.

Then all I needed was

  resolve: {
    alias: resolveBaseURL() // {"src":  srcDir}
  },

So I thought I could just replace that line with the plugin. And have TSConfig be the source of truth.

But I think, you had a different idea? You would write to the TSConfig or make an in-memory version of it?

Can I suggest an alternative approach?

Make them mutually exclusive. The arguments either take (almost) all the Omit<Options, 'tsconfig'> it currently take, or tsconfigPath.

From TSConfig, you don't need to recursively loop through directories or all that jazz, the definitions are already made for you, things like baseURL and aliases are defined by the user.

This guy got the right idea.

Subwaytime commented 2 years ago

The Idea of vite-aliases is to generate aliases based on your folder structure and create a js/ts config along side it, so you dont have define it at all.

Technically speaking, its pretty easy to extend with an existing tsconfig, but that kinda defeats the purpose of this package.

If i understand your proposal right..

seivan commented 2 years ago

This definition is it just in memory or one the file system? The problem would be that the type checker would complain if you don’t have it on tsconfig as well.

But if you need it there as well the file system then my guess is it would cause issues if they mismatch, am I wrong?

Subwaytime commented 2 years ago

As the package runs every time you run your normal vite build/dev, the ts/js config gets rewritten same for the vite-aliases config. So there shouldnt be a mismatch.

seivan commented 2 years ago

Oh ok. Thanks for clarifying that.