Rollup 构建TS项目
项目结构
tsconfig.json
tsc --init
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6tO01duX-1667465752105)(/Users/chenzhonghai/Desktop/截屏2022-10-06 19.33.04.png)]
package.json
{
"name": "study",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"bulid":"rollup -c",
"dev":"rollup -c -w"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"cross-env": "^7.0.3",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.1",
"typescript": "^4.5.5"
}
}
npm install -y
rollup.config.js
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import server from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
export default{
input:"./src/index.ts",
output:{
file:path.resolve(__dirname,'./lib/index.js'),
format:'umd',
sourcemap:true
},
plugins:[
ts(),
livereload(),
terser(),
server({
open:true,
port:1988,
openPage:"/public/index.html"
})
]
}
最后将tsconfig.js的module改为ES2015