How to configure tsconfig.json to output files from multiple source folders to single flat outDir?

后端 未结 3 764
青春惊慌失措
青春惊慌失措 2021-01-15 11:20

I have multiple typescript projects (e.g. client and server), which share some common functionality (located in a common fold

相关标签:
3条回答
  • 2021-01-15 12:08

    And now we have the support for project references in Typescript 3.0 (i.e. cascade build of multiple Typescript projects). We can also control the output location of the tsc builds.

    https://blogs.msdn.microsoft.com/typescript/2018/07/30/announcing-typescript-3-0/#project-references

    If a Typescript project 'bar' uses project 'foo', here is how you chain them:

    // ./src/bar/tsconfig.json
    {
        "compilerOptions": {
            // Needed for project references.
            "composite": true,
            "declaration": true,
    
            // Other options...
            "outDir": "../../lib/bar",
            "strict": true, "module": "esnext", "moduleResolution": "node",
        },
        "references": [
            { "path": "../foo" }
        ]
    }
    

    Thanks, TS guys!

    0 讨论(0)
  • 2021-01-15 12:13

    As of now, you can't.

    I am in a situation similar to yours, I have looked around but it seems like there is no way to change this behaviour with TypeScipt configuration.

    The best you can do is use something else (a Grunt task, a shell script, ...) for moving the js files and deleting the generated folders, after every build.

    0 讨论(0)
  • 2021-01-15 12:14

    I've solved this problem in my current project (which has the same setup) by putting a link to the common lib into both sources.

    common/
      src/
        lib/
    client/
      src/
        lib/ -> $PROJECT_PATH/common/src/lib/
    server/
      src/
        lib/ -> $PROJECT_PATH/common/src/lib/
    

    Compilation and bundling become transparent as the tools treat that directory as a local one.

    0 讨论(0)
提交回复
热议问题