npm install typescript -g tsc --init # 户帮我们生成tsconfig.json tsc # 可以将ts文件编译成js文件,会在当前目录下生成js文件,不写文件名字的话,就全都编译了 tsc --watch # 监控ts文件变化生成js文件
npm install rollup typescript rollup-plugin-typescript2 @rollup/plugin-node-resolve rollup-plugin-serve -D
npx tsc --init
// rollup.config.js import ts from 'rollup-plugin-typescript2' import {nodeResolve} from '@rollup/plugin-node-resolve'; import serve from 'rollup-plugin-serve'; import path from 'path' export default { input:'src/index.ts', output:{ format:'iife', file:path.resolve('dist/bundle.js'), sourcemap:true }, plugins:[ nodeResolve({ extensions:['.js','.ts'] }), ts({ tsconfig:path.resolve(__dirname,'tsconfig.json') }), serve({ open:true, openPage:'/public/index.html', port:3000, contentBase:'' }) ] }
"scripts": { "dev": "rollup -c -w" }
npm run dev