LeDDGroup / typescript-transform-paths

Transforms module resolution paths using TypeScript path mapping and/or custom paths
MIT License
465 stars 22 forks source link

how to use with tsc? #151

Closed dcsan closed 2 years ago

dcsan commented 2 years ago

To compile with tsc — Use ts-patch

could you give an example please? i've looked ts-patch docs but not clear how to combine these both.

I was hoping I can just add something to my package.json like this:

"paths": "tsconfig-replace-paths -s ./ --project tsconfig.json"
nonara commented 2 years ago

Hi, @dscan

To use with both, simply follow both instructions.

For typescript-transform-paths perform the step in 1. Install and 2. Configure

Then for ts-patch follow steps: 1, 2, & 3.

After you do, whenever tsc is run, it will transform your paths

Hope that helps!

marcellino-ornelas commented 1 year ago

@nonara can you provide an example? its still not very clear what we need to do. I followed ts-patch instructions & your instructions and I still don't have any of my aliases changed

nonara commented 1 year ago

@marcellino-ornelas You can see it in action here https://github.com/nonara/slonik-plus

Note the package.json prepare script and the two plugins entries in the tsconfig.json file. Also the paths config in the same.

marcellino-ornelas commented 1 year ago

I wasnt able to get the ts-patch working correctly and link to the repo took me to a 404 but I got it working by installing ttypescript

adding the following code to tsconfig.json

{
    "compilerOptions": {
                 /* other code */
        "plugins": [
            { "transform": "typescript-transform-paths" },
            { "transform": "typescript-transform-paths", "afterDeclarations": true }
        ]
    },
}

after that ttsc got everything working 🙌🏽

nonara commented 1 year ago

Didn't realize the repo was private. It's public now. Glad you got it working!