#tsc output tree

65 messages · Page 1 of 1 (latest)

silk hearth
#

When compiling my code with tsc, If I have something like:

- src
  - index.ts
- tsconfig.json

it will get compiled into:

- dist
  - index.ts

How to make it compile into:

- dist
  - src
    - index.ts
earnest storm
#
{
    "compilerOptions": {
        "rootDir": "src",
        "outDir": "dist/src"
    }
}
silk hearth
#

I meant to say that I would like to get it compiled exactly as it is

earnest storm
#

What is your rootDir set to?

silk hearth
#

didn't set it

earnest storm
#

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.

silk hearth
#
{
  "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/**/*"
  ]
}
earnest storm
#

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?

earnest storm
#

Yeah.

silk hearth
#

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

lavish sage
#

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

earnest storm
#

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.

silk hearth
#

oh

#

it I set rootDir on .

#

it will maintain my structure

#

without changing it

#

perfect

earnest storm
#

It is as @lavish sage says, TypeScript is trying to help by having rootDir default to src when left out.

lavish sage
#

yeah, that's a pretty common setup

silk hearth
#

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

lavish sage
#

just curious: what files outside of src do you want to compile and ship as part of your package?

silk hearth
#

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

lavish sage
#

ah, i see. yeah probably a good idea to have a more deterministic base config

silk hearth
#

but, some people prefer typings/ outside

#

so; I think I gotta

lavish sage
#

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

silk hearth
#

what is better in ur opinion?

#

put every ts file inside src?

silk hearth
#

keeping outside of src only files like tsconfig, gitignore, package.json, and etc..

lavish sage
#

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

silk hearth
#

so, I could set include: ["src/**/*"]

silk hearth
lavish sage
#

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/

silk hearth
#

I'll put everything inside src

#

ok

#

It's better I think

lavish sage
#

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)

silk hearth
silk hearth
lavish sage
#

yeah