vike icon indicating copy to clipboard operation
vike copied to clipboard

Support any path alias

Open brillout opened this issue 1 year ago • 9 comments

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 avatar Sep 26 '23 08:09 brillout

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?

arthurgailes avatar Oct 16 '23 14:10 arthurgailes

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.

brillout avatar Oct 16 '23 14:10 brillout

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

jurijzahn8019 avatar Oct 17 '23 07:10 jurijzahn8019

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

brillout avatar Oct 17 '23 09:10 brillout

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

mikew avatar Dec 02 '23 15:12 mikew

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 avatar Dec 02 '23 19:12 brillout

Another problematic library: https://github.com/vikejs/vike/discussions/1356.

brillout avatar Dec 14 '23 13:12 brillout

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.

dmytro-grablov avatar Jan 12 '24 13:01 dmytro-grablov

@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 avatar Jan 13 '24 10:01 brillout

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 https://github.com/vikejs/vike/issues/1567 is implemented.

brillout avatar Mar 20 '24 17:03 brillout

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

brillout avatar Mar 20 '24 17:03 brillout