microsoft / TypeScript-React-Starter

A starter template for TypeScript and React with a detailed README describing how to use the two together.
MIT License
11.08k stars 1.21k forks source link

Resolve alias #84

Open tarhunakau opened 6 years ago

tarhunakau commented 6 years ago

Hi, there is issue with aliases... I have tried to find a solution but still no luck. Could you please inplement ability to make path aliases for webpack? The full chain of resolving should be for TSLint, code imports and tests both...

DanielRosenwasser commented 6 years ago

Could you elaborate a bit? If you mean that you've tried ejecting and modifiying the resolve field, I'm not necessarily sure whether that's something we can control.

fruitraccoon commented 6 years ago

@BLRplex I'm not sure if this helps, but I've updated my module resolution to allow "root-relative" imports using a combination of create-react-apps NODE_PATH environment variable and TypeScript's paths setting in .tsconfig.

The paths setting may let you do what you're after with aliases?

tarhunakau commented 6 years ago

I have solved issue by ejecting kit. NODE_PATH does not help for tests. It helps with imports for building app, but does not help for running tests. I also have tried to put additional settings in package.json, but you have allowed only 4 properties for overriding. The necessary one is banned. So, the issue is not actual for me anymore. After ejecting config I have put all changes in configs. And it works for me.

aacanakin commented 6 years ago

@BLRplex Is this currently possible without ejecting?

tronza commented 6 years ago

I use this kind of solution in tsconfig.json:

"compilerOptions": {
  ...
  "baseUrl": "./src",
  "paths": {
    "custom_modules": ["./src/mymodules"]
  }
}

And for tests I added to .env-file in the package.json level the following:

NODE_PATH=src

Hopefully this helps.