Rollup 构建TS项目

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值