diff --git a/packages/istanbul-widget/CHANGELOG.md b/packages/istanbul-widget/CHANGELOG.md index 88519ae..0da4b40 100644 --- a/packages/istanbul-widget/CHANGELOG.md +++ b/packages/istanbul-widget/CHANGELOG.md @@ -1,5 +1,11 @@ # istanbul-widget +## 1.3.2 + +### Patch Changes + +- iife: mount the istanbul instance on Window + ## 1.3.1 ### Patch Changes diff --git a/packages/istanbul-widget/README.md b/packages/istanbul-widget/README.md index 27f3bf6..a28460d 100644 --- a/packages/istanbul-widget/README.md +++ b/packages/istanbul-widget/README.md @@ -4,14 +4,14 @@ 如果你使用vite作为开发框架,推荐使用 `vite-plugin-istanbul-widget` -## 安装 +## 上手 + +### 方法一:使用 npm ```bash npm install istanbul-widget ``` -## 使用 - ```ts import { IstanbulWidget } from 'istanbul-widget' @@ -26,6 +26,17 @@ const istanbulWidget = new IstanbulWidget({ }) ``` +### 方法二:使用CDN直接插入到HTML + +```html + + +``` + + ## 配置项 ```ts diff --git a/packages/istanbul-widget/iife.html b/packages/istanbul-widget/iife.html new file mode 100644 index 0000000..73b86de --- /dev/null +++ b/packages/istanbul-widget/iife.html @@ -0,0 +1,18 @@ + + + + + + + iife + + + + + + + + diff --git a/packages/istanbul-widget/package.json b/packages/istanbul-widget/package.json index dc50308..8ff06da 100644 --- a/packages/istanbul-widget/package.json +++ b/packages/istanbul-widget/package.json @@ -1,6 +1,6 @@ { "name": "istanbul-widget", - "version": "1.3.1", + "version": "1.3.2", "type": "module", "files": [ "**" diff --git a/packages/istanbul-widget/src/core/plugin/IstanbulWidgetReactPlugin.ts b/packages/istanbul-widget/src/core/plugin/IstanbulWidgetReactPlugin.ts index 4fe659b..2423611 100644 --- a/packages/istanbul-widget/src/core/plugin/IstanbulWidgetReactPlugin.ts +++ b/packages/istanbul-widget/src/core/plugin/IstanbulWidgetReactPlugin.ts @@ -1,3 +1,4 @@ +import { isFunction } from '@minko-fe/lodash-pro' import React from 'react' import ReactDOM from 'react-dom/client' import { $ } from '@/utils/query' @@ -38,7 +39,7 @@ export class IstanbulWidgetReactPlugin extends IstanbulWidget public registerEvents() { const properties = Object.getOwnPropertyNames(IstanbulWidgetReactPlugin.prototype) - const onMethods = properties.filter((name) => name.startsWith('on') && typeof this[name] === 'function') + const onMethods = properties.filter((name) => name.startsWith('on') && isFunction(this[name])) onMethods.forEach((methodName) => { this[methodName].call(this) diff --git a/packages/istanbul-widget/src/istanbul-widget.iife.ts b/packages/istanbul-widget/src/istanbul-widget.iife.ts new file mode 100644 index 0000000..4869357 --- /dev/null +++ b/packages/istanbul-widget/src/istanbul-widget.iife.ts @@ -0,0 +1,5 @@ +// @ts-nocheck + +import { IstanbulWidget } from './core/core' + +window.IstanbulWidget = IstanbulWidget diff --git a/packages/istanbul-widget/tsup.config.ts b/packages/istanbul-widget/tsup.config.ts index 14ef93f..b9c5b5a 100644 --- a/packages/istanbul-widget/tsup.config.ts +++ b/packages/istanbul-widget/tsup.config.ts @@ -102,7 +102,7 @@ const common = (option: Options): Options => ({ }) const esmBundle: Options = { - format: ['esm'], + format: 'esm', entry: { 'istanbul-widget.esm': 'src/istanbul-widget.ts', }, @@ -120,9 +120,9 @@ const esmBundle: Options = { const iife: Options = { injectStyle: true, - format: ['iife'], + format: 'iife', entry: { - 'istanbul-widget.min': 'src/istanbul-widget.ts', + 'istanbul-widget.min': 'src/istanbul-widget.iife.ts', }, esbuildOptions(options) { if (!options.logOverride) { @@ -131,6 +131,7 @@ const iife: Options = { options.logOverride!['empty-import-meta'] = 'silent' }, dts: false, + minify: true, } const esmBundleless: Options = { @@ -138,7 +139,7 @@ const esmBundleless: Options = { dts: { entry: getEntry('src/**/*.{ts,tsx}'), }, - format: ['esm'], + format: 'esm', outDir: 'dist/es', outExtension: () => ({ js: '.js' }), esbuildPlugins: [fileSuffixPlugin('esm')], diff --git a/packages/vite-plugin-istanbul-widget/CHANGELOG.md b/packages/vite-plugin-istanbul-widget/CHANGELOG.md index 9dec96b..1d8d31b 100644 --- a/packages/vite-plugin-istanbul-widget/CHANGELOG.md +++ b/packages/vite-plugin-istanbul-widget/CHANGELOG.md @@ -1,5 +1,13 @@ # vite-plugin-istanbul-widget +## 1.3.2 + +### Patch Changes + +- docs update +- Updated dependencies + - istanbul-widget@1.3.2 + ## 1.3.1 ### Patch Changes diff --git a/packages/vite-plugin-istanbul-widget/README.md b/packages/vite-plugin-istanbul-widget/README.md index 5215901..82c68b6 100644 --- a/packages/vite-plugin-istanbul-widget/README.md +++ b/packages/vite-plugin-istanbul-widget/README.md @@ -42,23 +42,29 @@ export default defineConfig((env) => ({ ```ts type VitePluginIstanbulWidgetOptions = { - /** - * 入口文件,默认读取 src/main.{ts,tsx} - * @default 'src/main.{ts,tsx}' - */ - entry?: string; - /** - * 是否开启插件 - */ - enabled?: boolean; - /** - * vite-plugin-istanbul 配置 - */ - istanbulPluginConfig?: IstanbulPluginOptions; - /** - * istanbul-widget 配置 - * @description false 时则关闭 istanbulWidget 控件 - */ - istanbulWidgetConfig: IstanbulWidgetOptions | false; + /** + * 入口文件 + * @default 'src/main.{ts,tsx}' + */ + entry?: string + /** + * 是否开启插件 + * @default false + */ + enabled?: boolean + /** + * 全量上报 + * @default true + */ + fullReport?: boolean + /** + * vite-plugin-istanbul 配置 + */ + istanbulPluginConfig?: IstanbulPluginOptions + /** + * istanbul-widget 配置 + * @description false 则关闭 istanbul-widget 控件 + */ + istanbulWidgetConfig: IstanbulWidgetOptions | false } ``` diff --git a/packages/vite-plugin-istanbul-widget/package.json b/packages/vite-plugin-istanbul-widget/package.json index 0993320..238b97f 100644 --- a/packages/vite-plugin-istanbul-widget/package.json +++ b/packages/vite-plugin-istanbul-widget/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-istanbul-widget", - "version": "1.3.1", + "version": "1.3.2", "type": "module", "main": "./dist/index.cjs", "module": "./dist/index.js", diff --git a/packages/vite-plugin-istanbul-widget/src/index.ts b/packages/vite-plugin-istanbul-widget/src/index.ts index 924ce23..aa4e07d 100644 --- a/packages/vite-plugin-istanbul-widget/src/index.ts +++ b/packages/vite-plugin-istanbul-widget/src/index.ts @@ -8,7 +8,7 @@ import glob from 'tiny-glob' import istanbul, { type IstanbulPluginOptions } from 'vite-plugin-istanbul' import serialize from '../serialize' -type VitePluginIstanbulWidgetOptions = { +export type VitePluginIstanbulWidgetOptions = { /** * 入口文件 * @default 'src/main.{ts,tsx}'