Webpack resolve.alias does not work with typescript?

前端 未结 7 1166
日久生厌
日久生厌 2020-12-12 21:02

I try to shorten my imports in typescript

from import {Hello} from \"./components/Hello\";

to import {Hello} from \"Hello\";

<
7条回答
  •  时光取名叫无心
    2020-12-12 21:33

    I think you can do this and have it work the way you describe:

    resolve: {
        root: [
            path.resolve(__dirname),
             //e.g. path.resolve(__dirname, 'src', 'components')
        ], 
        extensions: ["", ".ts", ".tsx", ".js"]
    },
    

    Then you can do import {Hello} from "Hello";

    I know I do this to resolve file paths in my src/js directory. I am not using typescript though, but I don't think it would affect the result.

提交回复
热议问题