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.js
we 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.js
and 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"