Typescript tsconfig.json 详解

  • Post author:
  • Post category:其他


环境搭建

安装ts

npm i -g typescript

初始化工程

mkdir ts-demo
npm init -y 

安装rollup

npm i -g rollup
npm i rollup -D

添加rollup.config.js

touch rollup.config.js 
npm i rollup-plugin-json -D
npm i rollup-plugin-typescript typescript tslib  -D

import json from 'rollup-plugin-json';
import typescript from 'rollup-plugin-typescript';

export default {
  input: 'src/main.ts',
  output: {
    file: 'dist/app.js',
    format: 'cjs'
  },
  plugins: [ typescript() ]
};

package.json

{
  "name": "ts-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev-build": "rollup -c",
    "dev": "npm run dev-build && node ./dist/app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "rollup": "^1.27.5",
    "rollup-plugin-json": "^4.0.0",
    "rollup-plugin-typescript": "^1.0.1",
    "tslib": "^1.10.0",
    "typescript": "^3.7.2"
  }
}

main.ts

// src/main.ts
function greeter(person: string):string {
    return "Hello, 



版权声明:本文为hcz804933522原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。