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

Support any path alias #1146

Closed
brillout opened this issue Sep 26, 2023 · 11 comments
Closed

Support any path alias #1146

brillout opened this issue Sep 26, 2023 · 11 comments
Labels

Comments

@brillout
Copy link
Member

brillout commented Sep 26, 2023

Description

As discussed here it seems that Nx expects monorepo package names to start with @.

There is a Vike internal issue with path aliases that cannot be distinguished from npm package names. I've tried a workaround but couldn't make it work so far (but I'm fairly confident it's possible to make it work).

A warning should still be shown as defining indistinguishable path aliases is asking for trouble (as attested by Vike's internal issue with it). It also makes code less readable. In general, breaking implicit assumptions should be avoided as much as possible. Although Vike probably shouldn't show a warning for indistinguishable aliases set by Vite plugins the user has no control over with.

@brillout brillout added the enhancement ✨ New feature or request label Sep 26, 2023
@arthurgailes
Copy link
Contributor

Does this mean we can safely ignore the deprecation warning: defines an invalid resolve.alias which will be deprecated in the next major release: a path alias cannot start with @, see https://vike.dev/path-aliases#vite?

@brillout
Copy link
Member Author

If you want to be optimistic then yes go ahead. If you want to be conservative then wait until I find the solution (I'm fairly optimistic I will but I cannot guarantee it).

If I'm successful, there'll still be a warning (you should avoid breaking implicit conventions as much as possible) but you'll be able to suppress the warning and Vike will work just fine.

@jurijzahn8019
Copy link

Hi, i have a similar question about tilde. In my config I am using regex:

{
  resolve: {
    alias: [{ find: /^~(.*)$/, replacement: "$1" }],
  },
}

Although it would be possible to us string as pattern, I would like to ensure only aliases which begin with tilde should be processed.

So the question is what is the preferred way?

Thanks

@brillout
Copy link
Member Author

@jurijzahn8019 That's a neat alias. I think it should be possible/easy to analyze and whitelist such regex pattern.

@mikew
Copy link
Contributor

mikew commented Dec 2, 2023

Another +1, vike shouldn't dictate what a path alias starts with.

@brillout
Copy link
Member Author

brillout commented Dec 2, 2023

To be clear: I agree Vike shouldn't be prescriptive, it's just isn't as easy as it seems. But, as said, I think it's doable. Let's see.

@brillout brillout changed the title Support aliases starting with @ (and, in general, aliases that cannot be distinguished from npm package names) Support any path alias Dec 7, 2023
@brillout
Copy link
Member Author

Another problematic library: #1356.

@dmytro-grablov
Copy link

I am facing the similar problem.

In my case we have to use several vue libraries within a monorepo project, and bring them into one app. It may happen, that these packages have their own vue/vuex dependency and it is not preferable, to later have several vue/vuex instances on the same bundle. So normally the following alias solved this problem:

      {
        find: 'vue',
        replacement: fileURLToPath(new URL('node_modules/vue', import.meta.url)),
      },
      {
        find: 'vuex',
        replacement: fileURLToPath(new URL('node_modules/vuex', import.meta.url)),
      },

but now vike tells me that this syntax will soon be deprecated, although it looks like a valid case for its own need.
IMO as well, vike should not dictate how vite config should look like.

@brillout
Copy link
Member Author

@dmytro-grablov I see, makes sense. FYI removing the warning (and resolving the issue beyond the warning) is high priority, which I'll implement as soon as all urgent tickets are implemented.

@brillout
Copy link
Member Author

Vike now officially supports any path alias.

Pre-released in 0.4.166-commit-6a8acaa. Release ETA this week.

Note that a warning (that you'll be able to suppress) will still be shown after #1567 is implemented.

brillout added a commit that referenced this issue Mar 20, 2024
@brillout
Copy link
Member Author

Btw. Vike is looking for sponsors, any amount is appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants