美文网首页Java 核心技术Node.js
Web and Node environment configu

Web and Node environment configu

作者: 梁同桌 | 来源:发表于2018-06-28 18:59 被阅读3次

    Node

    1. install
    npm init 
    npm install -g typescript
    tsc -init
    
    1. Add outDir and include to the file tsconfig.json file
    {
      "compilerOptions": {
       .....
       "outDir": "./dist",
      },
      "include": [
        "src/**/*",
      ]
    }
    
    1. 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

    1. 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"
    }
    
    1. 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"
      },
    
    1. 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。

    相关文章

      网友评论

        本文标题:Web and Node environment configu

        本文链接:https://www.haomeiwen.com/subject/vnsnyftx.html