ReasonJun

Typescript : tsconfig.json 본문

Frontend/Typescript

Typescript : tsconfig.json

ReasonJun 2023. 6. 10. 14:52
728x90

The tsconfig.json file is a configuration file used in TypeScript projects to specify compiler options and project settings. It allows you to customize how TypeScript compiles your code and provides control over various aspects of the compilation process.

 

Here are some common attributes that can be configured in the tsconfig.json file:

{
    "compilerOptions": {
        // ES(JS) version to be compiled- "ES2015" recommended
        "target": "ES2015",

        // Module system designation - "CommonJS", "AMD", "ESNext" >>>  I will use the latest version of the ECMAscript.
        "module": "ESNext",

        // Module analysis method specification - "Node", "Classic" >>> The index file of any file can bring the function/variable to the import without specifying the path separately.
        "moduleResolution": "Node",

        // ESM Modular Compatibility Enabled? >>> 
        // The commonJS method does not support basic export like export default. In js, you need to import it with import * as commonjs from './common'
        // Since it is very inconvenient to set it differently each time you do import/export like this, set it to true so that it can be integrated and used in the same way as import commonjs form './common'.
        // ESM method and CommonJS method are not distinguished. >>> true
        "esModuleInterop": true,

        // All files are compiled as modules, import or export keywords are required
        // If true, an error occurs when there is no import or export in the file.
        "isolatedModules": false,

        // Specify the base path to use for module resolution
        "baseUrl": "./",

        // Specifies the path of the type declaration (d.ts) to be referenced by the compiler
        "typeRoots": ["./node_modules/@types"],

        // Specify library to use in compilation - "ESNext", "DOM"
        "lib": ["ESNext", "DOM"],

        // Enabling stricter type detection
        "strict": true, 
    },  
    // File path list to compile
    "include": [
        "src/**/*.ts"
    ],
    // File path list to exclude the compilation
    "exclude": [
        "node_modules"
    ]
}

// include: Specifies the path where typescript can be found in any part of the project.
// scr/**/*.ts: I will include all ts in src subfiles.

// exclude: Specify paths to exclude when compiling
// node_modules: This don't need it when compiling. It is for storing packages, not for compiling them.
728x90
Comments