Skip to content

Commit

Permalink
fix: css compatibility
Browse files Browse the repository at this point in the history
release
  • Loading branch information
hemengke1997 committed Apr 16, 2024
1 parent 9bd4617 commit 3e10350
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 108 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dev": "turbo dev --filter=\"./packages/*\"",
"build": "turbo build --filter=\"./packages/*\"",
"lint": "turbo lint --filter=\"./packages/*\"",
"prepare": "simple-git-hooks",
"commitlint": "commitlint -e",
"up": "taze -I -w",
"bump": "changeset",
Expand Down
1 change: 1 addition & 0 deletions packages/istanbul-widget/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
6 changes: 6 additions & 0 deletions packages/istanbul-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# istanbul-widget

## 1.0.1

### Patch Changes

- css compatibility

## 1.0.0

### Major Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/istanbul-widget/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ new IstanbulWidget({
report: {
onAction: async (coverage) => {
console.log('上报', coverage)
throw new Error('上报失败')
},
requireReporter: true,
requireReporter: false,
},
})
6 changes: 3 additions & 3 deletions packages/istanbul-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "istanbul-widget",
"version": "1.0.0",
"version": "1.0.1",
"type": "module",
"main": "./dist/istanbul-widget.min.js",
"module": "./dist/istanbul-widget.esm.js",
Expand All @@ -27,7 +27,6 @@
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-toast": "^1.1.5",
"bits-ui": "^0.21.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"destr": "^2.0.3",
Expand All @@ -46,8 +45,9 @@
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"rollup-plugin-visualizer": "^5.12.0",
"tailwindcss": "^3.4.3",
"tailwindcss": "3.2.7",
"tailwindcss-rem-to-px": "^0.1.0",
"terser": "^5.30.3",
"vite": "^5.0.8",
"vite-plugin-css-injected-by-js": "^3.5.0",
"vite-plugin-dts": "^3.8.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
plugins: {
'tailwindcss/nesting': {},
'tailwindcss': {},
Expand Down
15 changes: 11 additions & 4 deletions packages/istanbul-widget/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import '@/styles/global.css'
const default_interval = 60
const default_min_interval = 10

export const enum WIDGET_STORAGE {
ENABLE_AUTO_REPORT = 'enable_auto_report',
REPORT_INTERVAL = 'report_interval',
REPORT_ON_PAGELEAVE = 'report_on_pageleave',
REPORTER = 'reporter',
}

export class IstanbulWidget {
public version: string = __VERSION__
public isInited: boolean = false
Expand Down Expand Up @@ -114,10 +121,10 @@ export class IstanbulWidget {
reporter: '',
}

const enable_auto_report = getStorage('enable_auto_report', originData.enable_auto_report)
const report_interval = getStorage('report_interval', originData.report_interval)
const report_on_pageleave = getStorage('report_on_pageleave', originData.report_on_pageleave)
const reporter = getStorage('reporter', originData.reporter)
const enable_auto_report = getStorage(WIDGET_STORAGE.ENABLE_AUTO_REPORT, originData.enable_auto_report)
const report_interval = getStorage(WIDGET_STORAGE.REPORT_INTERVAL, originData.report_interval)
const report_on_pageleave = getStorage(WIDGET_STORAGE.REPORT_ON_PAGELEAVE, originData.report_on_pageleave)
const reporter = getStorage(WIDGET_STORAGE.REPORTER, originData.reporter)

const setConfigToLocal = (data: Config) => {
Object.keys(data).forEach((key) => {
Expand Down
File renamed without changes.
26 changes: 24 additions & 2 deletions packages/istanbul-widget/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import react from '@vitejs/plugin-react'
import path from 'node:path'
import { visualizer as rollupVisualizer } from 'rollup-plugin-visualizer'
import { minify } from 'terser'
import { type PluginOption, defineConfig } from 'vite'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import dts from 'vite-plugin-dts'
Expand All @@ -18,6 +19,22 @@ function visualizer() {
return undefined
}

function minifyBundles(): PluginOption {
return {
name: 'minifyBundles',
async generateBundle(_, bundle) {
for (const key in bundle) {
if (bundle[key].type === 'chunk' && key.endsWith('.js')) {
// @ts-expect-error
const minifyCode = await minify(bundle[key].code, { sourceMap: false })
// @ts-expect-error
bundle[key].code = minifyCode.code
}
}
},
}
}

// https://vitejs.dev/config/
export default defineConfig((env) => {
return {
Expand All @@ -30,6 +47,7 @@ export default defineConfig((env) => {
root: __dirname,
include: ['src/**/*'],
}),
minifyBundles(),
],
resolve: {
alias: [{ find: '@', replacement: path.resolve(__dirname, './src') }],
Expand All @@ -39,14 +57,18 @@ export default defineConfig((env) => {
'process.env.NODE_ENV': JSON.stringify(env.mode),
},
build: {
target: ['es2015'],
sourcemap: env.mode !== 'production',
lib: {
entry: path.resolve(__dirname, 'src/istanbul-widget.ts'),
name: 'istanbul-widget',
fileName: (format) => (format === 'es' ? `istanbul-widget.esm.js` : 'istanbul-widget.min.js'),
fileName: (format) =>
({
umd: `${pkg.name}.min.js`,
es: `${pkg.name}.esm.js`,
})[format],
formats: ['umd', 'es'],
},
minify: true,
cssCodeSplit: false,
rollupOptions: {
treeshake: true,
Expand Down
7 changes: 7 additions & 0 deletions packages/vite-plugin-istanbul-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# vite-plugin-istanbul-widget

## 1.0.1

### Patch Changes

- Updated dependencies
- istanbul-widget@1.0.1

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-istanbul-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-istanbul-widget",
"version": "1.0.0",
"version": "1.0.1",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
Loading

0 comments on commit 3e10350

Please sign in to comment.