tleunen / babel-plugin-module-resolver

Custom module resolver plugin for Babel
MIT License
3.46k stars 205 forks source link

Alias syntax for multi-level paths? #368

Open kylegillen opened 5 years ago

kylegillen commented 5 years ago

Hi.

So I have the following structure: src/lessons/01/Lesson01.tsx I've setup the following in my babel.config.js

[
  'module-resolver',
  {
    root: './src',
    alias: {
      lessons: ([, subDir]) => {
        return `./src/lessons${subDir}`
      },
    },
  },
],

The following statement resolved correctly as I have an index.ts file in the lessons directory: import Lesson1 from 'lessons'. However, if I try to access the following import Lesson1 from 'lessons/01/Lesson1' I get the following error message: Unable to resolve "./lessons/index.ts/01/Lesson01" from "src/index.tsx"

So it seems as though the file name of the file referencing the alias is being added to the path structure: ./lessons/index.ts/01/Lesson01.

Could someone enlighten me on how to make this work please? Thanks in advance.