Dave Clark IO

TypeScript Development for CRM - Keep it clean

One annoyance many developers face when using TypeScript is file layout within the IDE.

Apr 23rd 2017ยท2 min read
dirty rugby

More recently, applications built to integrate with CRM, either as external SPAs or HTML pages embedded within CRM, have utilised the TypeScript superset of JavaScript. If you're not already using TypeScript, see this great StackOverflow answer on why you should consider it (though this answer is general and not specific to Dynamics CRM development).

One annoyance many developers face when using TypeScript is file layout within the IDE. TypeScript compiles from .ts files to multiple .js files which can clutter file hierarchy layout on the IDE interface. This can be resolved in one of two ways.

1. Change your output directory

Navigate to your tsconfig.json file and specify an output directory that is different to the location of your .ts files. This could be /dist or /build:
"compilerOptions": {
    "outDir": "DIRECTORY"
    ...

2. Hide your .js files

Changing your output directory and moving your .js files can cause issues. For example an index.html page that references main.js will no longer work if you're now compiling to /dist/main.js. You may therefore consider whether you just want to hide your .js files from your IDE.

In Visual Studio Code, go to File > Preferences > Settings or your .vscode\settings.json file and enter:

"files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/*.js" : {
        "when": "$(basename).ts"
    },
    "**/*.js.map": {
        "when": "$(basename)"
    }
}

To hide .js files one file directory deeper, add further lines to your .json file with an additional /*:

"**/*/*.js": {
    "when": "$(basename).ts"
},
"**/*/*.js.map": {
    "when": "$(basename)"
}
Before
With .js files
After
Without .js files
Dave Clark IO
AboutLinkedInTwitterGitHub