#tsc output tree
65 messages · Page 1 of 1 (latest)
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist/src"
}
}
I dont mean this
I meant to say that I would like to get it compiled exactly as it is
What is your rootDir set to?
didn't set it
The contents of the rootDir will map exactly to the contents of the outDir.
If your rootDir is your project root (the folder with src and tsconfig.json), and your outDir is dist then you'll get the behavior you want.
{
"compilerOptions": {
"lib": [
"ESNext",
"DOM"
],
"baseUrl": "./",
"module": "ESNext",
"moduleResolution": "NodeNext",
"target": "ESNext",
"outDir": "dist",
"sourceMap": false,
"inlineSourceMap": true,
"removeComments": true,
"allowJs": true,
"resolveJsonModule": true,
"importHelpers": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"preserveConstEnums": true,
"skipLibCheck": true,
"allowUnreachableCode": false,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules/**/*"
]
}
If your rootDir is src (recommended) then set your outDir to dist/src to achieve what you desire.
You should get the behavior you want with that tsconfig.json. Are you not?
with mine?
Yeah.
It depends, if there are 2 dirs, it will create the 2 dirs inside the dist
if there is just one, it will just compile that dir and put only the files of the dir inside dist
i think there is magic defaulting for rootDir based on the input files that does something like find the longest directory prefix that contains all inputs
you can probably explicitly set rootDir to whatever you want it to be instead
Ah, that is annoying.
Explicitly set rootDir then.
I just tested and this works:
"rootDir": ".",
"outDir": "./dist",
You are correct, default rootDir does not result in expected behavior.
oh
it I set rootDir on .
it will maintain my structure
without changing it
perfect
It is as @lavish sage says, TypeScript is trying to help by having rootDir default to src when left out.
yeah, that's a pretty common setup
yeah, but, If I decide to delete other dirst and let only src
my package.json main
will give some problems
so, I had to get it compiled exactly as my structure
just curious: what files outside of src do you want to compile and ship as part of your package?
none, I mean, I usually compiled only src directory and put everything inside it.
But I got time now
and, cuz I always used a different
environment on every project
tsconfig, and etc
I want to make a base for my future projects
to use in almost every project
so, I'm just making a schema
u could say
ah, i see. yeah probably a good idea to have a more deterministic base config
I used to put typings/ in src/ for example, cuz I compiled just src
but, some people prefer typings/ outside
so; I think I gotta
i think i usually end up with a setup that's equivalent to "include": ["./src/**/*.ts"], so the default is usually what i want to happen
I actually prefer that, but don't know if it's better
keeping outside of src only files like tsconfig, gitignore, package.json, and etc..
generally, yeah i think i prefer that. src to me means "this is the only stuff that gets compiled to build the project"
i might have some fancy multi-directory setups, but then i wouldn't name any of the directories src
so, I could set include: ["src/**/*"]
test files that gets compiled, it may be better to just put them inside of the src as well
depends how elaborate you want to be, but if you want to avoid including test stuff in your built package then you can have it live in another directory and use a separate tsconfig file for tests that includes both ./test/**/*.ts and ./src/**/*.ts or whatnot
but yeah i definitely have projects (especially applications rather than libraries) where i just dump tests into src/
mmh, how do u use multiple tsconfig in same project?
I'll put everything inside src
ok
It's better I think
you can use tsc --project tsconfig.test.json to use a custom config file
or --build i think too (which may be necessary if you are using project references)
and rootDir: "./src"
I could create a tests script in package.json that compiles only test folder that is ouside of src
yeah