I started working recently on a Vue 3 application which runs with vite and I am trying to restructure the directories so that I can group components and related sub-components in folders.
I am currently using /path/to/MyComponent/index.vue
to import the higher-hierarchy component, and I would like to write the import statement without specifying the file name, so that I could do something like this:
import MyComponent from `@/path/to/MyComponent`
where the files structure looks like the following:
path
│
└───to
│
└───MyComponent
│ index.vue
│ SubComponent.vue
│ ...
I tried to play with the resolve.alias
property in the vite.config.ts
file, but I wasn't successful. Anyone managed to achieve this?
This is one of the attempts:
export default defineConfig({
...
resolve: {
alias: [
{
find: "@",
replacement: fileURLToPath(new URL("./src", import.meta.url)),
},
{
find: /(^(?!.*[.](ts|js|tsx|jsx|vue|)$))/,
replacement: "$1/index.vue",
},
],
},
...