#Building a TS project & excluding certain directories

21 messages · Page 1 of 1 (latest)

cerulean mirage
#

When I build my project, it's also trying to build files outside of ./src. In my tsconfig.json file, I have:

  • "rootDir": "./src"
  • "outDir": "./build"

I have a folder with some random files that I want it to ignore, but it's counting them as input files and giving me two errors:

  1. Cannot write file '__' because it would overwrite input file.
  2. File '__' is not under 'rootDir' '/src'. 'rootDir' is expected to contain all source files

Is there a way to only build the files located in ./src and ignore other directories?

lethal sapphire
#

show your tsconfig > include/exclude/files

cerulean mirage
flint flint
#

They're under the root of the tsconfig, not under compilerOptions.

cerulean mirage
#

Just using include will only compile those files listed?

flint flint
#

include is where it starts - anything imported by an included file is also compiled

#

From the exclude docs:

Important: exclude only changes which files are included as a result of the include setting. A file specified by exclude can still become part of your codebase due to an import statement in your code, a types inclusion, a /// <reference directive, or being specified in the files list.

It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include setting finds.

cerulean mirage
#

Having include will automatically blacklist anything not mentioned, correct? (unless it's imported through an included file)

#

Seems to work that way. ty both

#

!close

cerulean mirage
broken vine
flint flint
#

Yeah, if I "include": ["src/foo/**/*"] and src/foo/foo.ts imports ../../bar/bar.ts then TS will compile src/bar/bar.ts even though it wasn't in include.

#

And it would do that even if I had exclude: ["src/bar"]

#

Though if you have rootDir: "src/foo" then it'll error instead

cerulean mirage
flint flint
#

I mean it's where TS starts looking for files to compile.