Node
- install
npm init
npm install -g typescript
tsc -init
- Add outDir and include to the file tsconfig.json file
{
"compilerOptions": {
.....
"outDir": "./dist",
},
"include": [
"src/**/*",
]
}
- Create a new index.ts the src directory, and write the
console.log(666);
4.Directory to execute tsc to generate dist files, and then execute node ./dist/index.js
tsc
node ./dist/index.js
export 666, stage comletion
- Configure automatic restart
npm install --save nodemon
Create a new nodemon.json in the root directory,copy the content
{
"ignore": [
"**/*.test.ts",
"**/*.spec.ts",
".git",
"node_modules"
],
"watch": [
"src",
],
"exec": "npm start",
"ext": "ts"
}
- package.json, Add start two lines of command
"scripts": {
"start": "tsc && NODE_ENV=development node ./dist/index.js ",
"dev": "./node_modules/nodemon/bin/nodemon.js"
},
- Start, complete full configuration
npm run dev
Web
- Configuring your own webpack is very troblesome ,With react cli。
create-react-app my-app --scripts-version=react-scripts-ts
cd my-app
npm run start
Ending
the environment configuration for TypeScript write games is complete。