Maintain src/ folder structure when building to dist/ folder with Typescript 3
I had a similar problem when initially converting to a Typescript project. I also set resolveJsonModule: true
and the src
directory was copied to the output dist
directory.
The underlying reason is that one of my source files require
d package.json at the root of the project. Once i removed that, tsc no longer added src to the dist directory.
In short, make sure you are not requiring files outside of your src directory.
Explanatory FAQ here: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-does---outdir-moves-output-after-adding-a-new-file
The upgrade from TypeScript 2 to 3 by itself shouldn't have changed the behavior; if we can confirm that it did, that may be a bug. In any case, check that the rootDir
compiler option points to your src
directory and not to the parent directory, because the structure under the rootDir
is what is mirrored under the outDir
.
The structure of the output directory is controlled by the rootDir
of the compilerOptions
. See documentation here, setting it to ./src
should solve the issue.
{ "compilerOptions": { "rootDir": "src", ... }, "include": [ "src/" ]}