Skip to content

Instantly share code, notes, and snippets.

@TeemuKoivisto
Last active April 22, 2017 15:11
Show Gist options
  • Save TeemuKoivisto/d301829a9ed74b24f47a37818acdfde1 to your computer and use it in GitHub Desktop.
Save TeemuKoivisto/d301829a9ed74b24f47a37818acdfde1 to your computer and use it in GitHub Desktop.
How to create a simple TypeScript app that is compiled into frontend library

Beginning

A short tutorial on how to create a basic TypeScript app for a game or another project targeted on frontend.

1. Setting up the project

Create a new folder for your project and cd there and type npm init to create package.json. Writer whatever you want there or just hit enter to each and then let's install typescript: npm i -S typescript. We could install it also globally for some ease of use BUT to me installing global dependencies are annoying so for now let's withold from doing so.

Instead let's add tsconfig.json manually to the root of our folder. This would be created with tsc --init but since we are now very stupid we'll do it manually. Copy & paste this inside of it:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false
    }
}

And there we go, now we have setup our project with TypeScript. Nothing to compile yet, but we're getting there next.

2. Creating the first files

Without any .ts files our project would be pretty awful so let's create some for our app. First create src folder to your root and then add file index.ts inside of it. This file will serve as an entry to our project and exposes the API outside for others to use.

Copy & paste this inside of it:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment