0

I'm writing a Vue application that has many components which are nested in different folders. My folder structure looks something like this:

src folder
+components folder 
++partA folder
+++A.vue
+++AA.ts
+++subA folder
++++AAA.ts
++partB
+++B.vue
+++BB.ts

Inside my typeScript files, I sometimes need to refer to one of the other components so I end up with code that looks like:

import { something } from '../../partB/BB'
import { another } from './subA/AAA'

Is there a way to setup webpack so that I can always specify the import path to my components relative to the root (src) folder rather than having a bunch of relative paths defined that are specific to the file which is using the import statement?

1 Answer 1

1

I found a solution by using webpack's resolve alias: https://webpack.js.org/configuration/resolve/

in conjunction with tsconfig.json (https://www.typescriptlang.org/docs/handbook/compiler-options.html). I needed to specify a baseUrl and paths to match what I have setup in my resolve alias.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.