Could you explain the distinction between rootDir and baseUrl in TypeScript?
Based on the documentation provided by TypeScript:
Base URL
It serves as the base directory for resolving non-relative module names. Refer to the Module Resolution documentation for further details.
On the other hand, rootDir is used to
Specify the root directory of input files, primarily utilized to control the output directory structure with --outDir.
In my tsconfig file, I have included
"baseUrl": "app/javascript/src",and I haven't made any entries for
rootDir
Is this configuration correct? (It seems to be functioning fine, but I'm uncertain about its correctness)
Update: Using rootDir resulted in errors because of absolute paths being used.
This represents my current tsconfig settings. (the baseUrl works correctly)
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"jsx": "react",
"target": "es5",
"allowSyntheticDefaultImports": true,
"baseUrl": "app/javascript/src",
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"skipLibCheck": true,
"allowJs": true,
"strict": true,
"outDir": "app/javascript/.dist",
},
"exclude": [
"node_modules",
"**/*.js",
"**/*.jsx"
],
"include": [
"**/*.ts",
"**/*.tsx"
],
"compileOnSave": false
}
For webpack, path resolutions are handled like this
resolved_paths: ['app/javascript/src', 'app/javascript']