You've already forked uniapp-error-monitor
✨ 主要更新: - 全面重写README.md,增强文档完整性和易读性 - 新增完整的使用示例和高级用法说明 - 重构代码架构,删除冗余文件,提升代码质量 - 添加TypeScript支持,增强类型安全 - 优化构建配置,支持多种输出格式(ESM/CJS/UMD) - 改进错误捕获机制,支持更多错误类型 📋 具体变更: - README: 从基础文档升级为完整的API参考和使用指南 - 构建: 删除build.sh,构建配置移至rollup.config.js - 类型: 添加index.d.ts,实现完整的TypeScript支持 - 示例: 新增USAGE_EXAMPLES.js提供详细使用示例 - 配置: 优化package.json脚本和依赖管理 🎯 技术提升: - 代码结构更清晰,维护性更好 - 类型安全性显著增强 - 文档质量和用户体验大幅提升 - 支持更多模块格式,兼容性更好 🔖 版本: 1.0.1 -> 1.1.0
102 lines
2.1 KiB
JavaScript
102 lines
2.1 KiB
JavaScript
import { defineConfig } from 'rollup'
|
|
import babel from '@rollup/plugin-babel'
|
|
import { terser } from 'rollup-plugin-terser'
|
|
import typescript from '@rollup/plugin-typescript'
|
|
|
|
const pkg = require('./package.json')
|
|
|
|
const external = [
|
|
'vue',
|
|
'vue3',
|
|
'@dcloudio/uni-app',
|
|
'@dcloudio/uni-core',
|
|
'uniapp'
|
|
]
|
|
|
|
// 复制 TypeScript 定义文件到 dist 目录
|
|
function copyTypescriptDefinitions() {
|
|
return {
|
|
name: 'copy-types',
|
|
writeBundle() {
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const srcTypesFile = path.resolve(__dirname, 'src/index.d.ts')
|
|
const destTypesFile = path.resolve(__dirname, 'dist/index.d.ts')
|
|
|
|
if (fs.existsSync(srcTypesFile)) {
|
|
fs.copyFileSync(srcTypesFile, destTypesFile)
|
|
console.log('✅ TypeScript definitions copied to dist/index.d.ts')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const plugins = [
|
|
typescript(),
|
|
babel({
|
|
babelHelpers: 'bundled',
|
|
extensions: ['.js', '.ts'],
|
|
exclude: ['node_modules/**'],
|
|
presets: [
|
|
['@babel/preset-env', {
|
|
modules: false,
|
|
targets: {
|
|
esmodules: true
|
|
}
|
|
}]
|
|
]
|
|
}),
|
|
copyTypescriptDefinitions()
|
|
]
|
|
|
|
export default defineConfig([
|
|
{
|
|
input: 'src/index.js',
|
|
output: [
|
|
// ESM 输出
|
|
{
|
|
file: pkg.module,
|
|
format: 'es',
|
|
sourcemap: true,
|
|
exports: 'named'
|
|
},
|
|
// UMD 输出 (用于浏览器)
|
|
{
|
|
file: pkg.browser,
|
|
format: 'umd',
|
|
name: 'UniAppErrorMonitor',
|
|
sourcemap: true,
|
|
globals: {
|
|
'vue': 'Vue'
|
|
},
|
|
exports: 'named'
|
|
},
|
|
// CommonJS 输出 (用于 Node.js)
|
|
{
|
|
file: pkg.main,
|
|
format: 'cjs',
|
|
sourcemap: true,
|
|
exports: 'named'
|
|
}
|
|
],
|
|
external,
|
|
plugins
|
|
},
|
|
// 生产环境构建 (压缩版本)
|
|
{
|
|
input: 'src/index.js',
|
|
output: [
|
|
{
|
|
file: pkg.browser.replace('.umd.js', '.umd.min.js'),
|
|
format: 'umd',
|
|
name: 'UniAppErrorMonitor',
|
|
sourcemap: false,
|
|
exports: 'named',
|
|
plugins: [terser()]
|
|
}
|
|
],
|
|
external,
|
|
plugins
|
|
}
|
|
]) |