This document is to start your and my projects
- git init
- yarn init -y
- yarn add typescript -D
- yarn tsc --init
- express is the example
- yarn add @types/express
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
"script": {
"dev": "ts-node-dev --respawn --transpileOnly --ignore-watch node_modules --no-notify src/server.ts"
}
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
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
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
Jest is a JS testing framework designed to ensure correctness of any JS codebase.
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.jswe need changed the preset
const { compilerOptions} = require('./tsconfig.json');
preset: 'ts-jest';
"env": {
"es2020": true,
"node": true,
"jest": true
}
Babel is a JS compile. Is a tool that helps you write code in the latest version of javascript
yarn add -D @babel/cli @babel/core @babel/node @babel/preset-env @babel/preset-typescript
- Make a new file with name 👉
babel.config.jsand add configurations bellow 🔽
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
'@babel/preset-typescript'
],
ignore: [
'**/*.spec.ts'
]
}
"scripts": {
"build": "babel src --extensions \*.js,.ts\* --out-dir dist --copy-files --no-copy-ignored",
}
"start": "node dist/server.js"