Controlling TypeScript compilation

Yellicode compiles TypeScript templates using an internal configuration. However, you might want to let your IDE do the compilation instead, or you might want to explicitly control how your templates are compiled using a custom tsconfig file.

Disabling TypeScript compilation

In this scenario, we assume that your templates are compiled by another tool, or that you write your templates in plain Javascript. If you want to disable compilation for all configured templates, simply set the compileTypeScript value in your codegenconfig.json to false.

{
    "templates": [
        {
        "templateFile": "./first.template.ts"
        },
        {
        "templateFile": "./second.template.ts"
        }
    ],
    "compileTypeScript": false
}    

If you want disable compilation for an individual template, change its extension to .js and keep compileTypeScript enabled.

{
    "templates": [
        {
            "templateFile": "./first.template.ts"
        },
        {
            "templateFile": "./second.template.js"
        }
    ],
    "compileTypeScript": true
}    

Note that, for templates for which compilation is disabled, Yellicode will watch changes to the corresponding Javascript files when in --watch mode.

Using a custom tsconfig.json file

If you want complete control over the TypeScript compilation but still want Yellicode to compile your templates, you can create a separate tsconfig.json file for Yellicode templates. If your project already has a tsconfig.json file, we recommend to use a different name, for example tsconfig.codegen.json. Then, in your codegenconfig.json file, point the typeScriptConfigFile property to this file:

{
    "templates": [
        {
            "templateFile": "./some.template.ts"
        }
    ],
    "compileTypeScript": true,
    "typeScriptConfigFile": "./tsconfig.codegen.json"
}    

Please make sure that your custom TypeScript configuration is compatible with Node.js. In particular, the module format must be set to commonjs. You can use the following configuration as a starting point. This example matches the configuration that Yellicode uses internally.

{
    "compilerOptions": {
        "target": "es2015", 
        "module": "commonjs",
        "inlineSourceMap": true,             
        "removeComments": true        
    }
}