Git Product home page Git Product logo

setup-ts's Introduction

Setup project typescript ๐Ÿ”„๐Ÿ†•

Starting a new project is always a challenge

TS CONFIG NODE

This document is to start your and my projects

Starting ( In this setup I'm using yarn but you can change all for npm) โœ…

- git init
- yarn init -y

Now install typescript as a development โœ…

- yarn add typescript -D
- yarn tsc --init

Some libraries require to install the typescript dependency โœ…

  • express is the example
- yarn add @types/express

Now for development install the "reload" typescript โœ…

yarn add ts-node-dev
  • This dependency execute tsc, node and nodemon.
  • tsc ๐Ÿ‘‰ transpile the code TS in JS
  • node ๐Ÿ‘‰ the engine of the code JS
  • nodemon ๐Ÿ‘‰ monitors the code

Write the script bellow in your package.json ๐Ÿ”ฝ โœ…

"script": {
  "dev": "ts-node-dev --respawn --transpileOnly --ignore-watch node_modules --no-notify src/server.ts"
}

Now on tsconfig.json โœ…

The transpile code must go to a separate folder for production

  • modify outDir and rootDir
"outDir": "./dist"
"rootDir": "./src"
  • You must verify your "target", the node can use JS version es2017 and by default TS use Vanilla JS
  • "removeComments": true ๐Ÿ‘‰ remove all comments on building process
  • Other amazing target is : "resolveJsonModule": true ๐Ÿ‘‰ this function allows you import json into the code

Config ESLINT ๐Ÿ†•

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs

Starting โœ…

yarn add eslint 
yarn eslint --init

The Eslint gives to you many options, choose the makes more sense for you.

Me ๐Ÿ‘‰ airbnb

Them, he gives you many options for plugins you must install, but the tool gives only install for npm and I using yarn, so we need just copy the code and write on terminal with yarn add

Config Jest ๐Ÿ†•

Jest is a JS testing framework designed to ensure correctness of any JS codebase.

Starting โœ…

yarn add jest -D
yarn jest --init 
  • the init gives you options, I choose (yes,node,no,yes) ever
  • To default Jest don't work with TS so we need instals other plugin
yarn add ts-jest -D
yarn add @types/jest -D
  • Into jest.config.js we need changed the preset
const { compilerOptions} = require('./tsconfig.json');

preset: 'ts-jest';

Into eslintrc.json must added ๐Ÿ”ฝ โœ…

"env": {
  "es2020": true,
  "node": true,
  "jest": true
}

Config BABEL ๐Ÿ†•

Babel is a JS compile. Is a tool that helps you write code in the latest version of javascript

Starting

yarn add -D @babel/cli @babel/core @babel/node @babel/preset-env @babel/preset-typescript
  • Make a new file with name ๐Ÿ‘‰ babel.config.js and add configurations bellow ๐Ÿ”ฝ
module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current'
        }
      }
    ],
    '@babel/preset-typescript'
  ],
  ignore: [
    '**/*.spec.ts'
  ]
}

Now in package.json we need create a script of build, into "scripts"

"scripts": {
  "build": "babel src --extensions \*.js,.ts\* --out-dir dist --copy-files --no-copy-ignored",
}

Lastly we make the script for run in production

"start": "node dist/server.js"

setup-ts's People

Contributors

henricop avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.