Search code examples
typescripttsconfig

TypeScript - outDir to a folder of another project


I have a solution that contains 2 projects (not 2 folders in a project):

  • Core: storing TS code
  • CrmPackage: storing JS code that can be deployed to the server

What I want: the output folder should be distributed in the CrmPackage project as following

  • Solution
    • Core
      • TS
        • Account
          • account.ts
      • tsconfig.json
    • CrmPackage
      • JS
        • Account
          • account.js

What I have tried: setting the "outDir" = "../CrmPackage/JS" in tsconfig.json, but it creates the folder CrmPackage/JS directly in the Core project.


Solution

  • I solved the problem as following:

    Solution 1:

    1. Set tsconfig.json to put all output js files into folder 'JS' in Core project: "outDir": "JS"
    2. Use Post-build actions in Visual Studio to copy the all folders & subfolders & files from 'JS' folder (in Core project) to 'WebResources' folder (in CrmPackage project): xcopy "$(ProjectDir)JS\*.*" "$(SolutionDir)CrmPackage\WebResources" /Y /I /E

    Solution 2:

    1. Simply use webpack to build and bundle typescript into the destination project