Webpack resolve.alias does not work with typescript?

前端 未结 7 1170
日久生厌
日久生厌 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:15

    If you're using ts-loader, you might have to synchronize your webpack alias/resolve settings with your paths setting in your tsconfig.json.

    {
        "compilerOptions": {
            "baseUrl": "./",
            "paths": {
                "Hello": ["src/components/Hello"]
            }
        }
    }
    

    If you're using awesome-typescript-loader, then webpack can figure this out automatically from the paths setting in your tsconfig.json, as per the status on this issue from the repo. That way, you don't need to duplicate the same information in your Webpack alias field.

提交回复
热议问题