TypeScript in the browser

If you are using TypeScript to create a web application here are my recommendations to get a quick TypeScript + React (my UI framework of choice) project setup.

General Machine Setup

Project Setup Quick

Use https://github.com/basarat/react-typescript as a base.

git clone https://github.com/basarat/react-typescript.git
cd react-typescript
npm install

Now jump to develop your amazing application

Project Setup Detailed

To see how that project is created, its documented below.

  • Create a project dir:
mkdir your-project
cd your-project
  • Create tsconfig.json:
  "compilerOptions": {
    "sourceMap": true,
    "module": "commonjs",
    "target": "es5",
    "jsx": "react",
    "lib": [
  "include": [
  "compileOnSave": false
  • Create package.json.
  "name": "react-typescript",
  "version": "0.0.0",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/basarat/react-typescript.git"
  "scripts": {
    "build": "webpack -p",
    "start": "webpack-dev-server -d --content-base ./public"
  "dependencies": {
    "@types/react": "16.4.2",
    "@types/react-dom": "16.0.6",
    "react": "16.4.1",
    "react-dom": "16.4.1",
    "ts-loader": "4.4.1",
    "typescript": "2.9.2",
    "webpack": "4.12.1",
    "webpack-cli": "3.0.8",
    "webpack-dev-server": "3.1.4"
  • Create a webpack.config.js to bundle your modules into a single app.js file that contains all your resources:
module.exports = {
  entry: './src/app/app.tsx',
  output: {
    path: __dirname + '/public',
    filename: 'build/app.js'
  resolve: {
    extensions: ['.ts', '.tsx', '.js']
  module: {
    rules: [
      { test: /\.tsx?$/, loader: 'ts-loader' }
  • public/index.html file that will be served from your webserver:
      <div id="root"></div>
      <script src="./build/app.js"></script>
  • src/app/app.tsx that is your frontend application entry point:
import * as React from 'react';
import * as ReactDOM from 'react-dom';

const Hello: React.SFC<{ compiler: string, framework: string }> = (props) => {
  return (

  <Hello compiler="TypeScript" framework="React" />,

Develop your amazing application

You can get the latest packages using npm install typescript@latest react@latest react-dom@latest @types/react@latest @types/react-dom@latest webpack@latest ts-loader@latest webpack-dev-server@latest webpack-cli@latest --save-exact

  • Do live development by running npm start.
  • Build production assets by running npm run build.
    • Serve the public folder (which contains the built assets) from your server.

results matching ""

    No results matching ""