feat(): 改为vite

This commit is contained in:
2026-03-16 17:58:57 +08:00
parent cd734d8524
commit 1ccbd4e872
74 changed files with 46574 additions and 2145 deletions
+1332
View File
File diff suppressed because it is too large Load Diff
+37
View File
@@ -0,0 +1,37 @@
{
"name": "@r-utils/vue2",
"version": "1.0.0",
"private": true,
"description": "Vue2工具库",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./*": "./*"
},
"keywords": [
"vue2"
],
"scripts": {
"build": "vite build",
"watch": "vite build --watch",
"lint": "eslint --ext .js,ts --fix src",
"release": "standard-version",
"commit": "cz",
"lint-staged": "lint-staged",
"test": "jest"
},
"dependencies": {
"lodash": "^4.17.21"
},
"devDependencies": {
"vue": "^2.7.0"
}
}
+2
View File
@@ -0,0 +1,2 @@
export { default } from "./plugins/visibility";
export { default as VisibilityPlugin } from "./plugins/visibility";
+46
View File
@@ -0,0 +1,46 @@
function install(Vue) {
Vue.mixin({
created() {
const onShowHook = this.$options.onShow;
const onHideHook = this.$options.onHide;
if (onShowHook != null || onHideHook != null) {
this.visibilitychangeCallback();
document.addEventListener(
"visibilitychange",
this.visibilitychangeCallback
);
}
},
destroyed() {
document.removeEventListener(
"visibilitychange",
this.visibilitychangeCallback
);
},
methods: {
visibilitychangeCallback() {
const onShowHook = this.$options.onShow?.bind(this);
const onHideHook = this.$options.onHide?.bind(this);
if (document.visibilityState == "visible") {
console.log("visible");
if (typeof onShowHook === "function") {
onShowHook();
}
}
if (document.visibilityState == "hidden") {
console.log("hidden");
if (typeof onHideHook === "function") {
onHideHook();
}
}
},
},
});
}
export default {
install,
};
+21
View File
@@ -0,0 +1,21 @@
{
"exclude": ["node_modules", "dist"],
"include": ["src/**/*.ts", "src/**/*.js"],
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "bundler",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["dom", "esnext"],
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
},
"allowJs": true
}
}
+31
View File
@@ -0,0 +1,31 @@
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs'],
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
},
rollupOptions: {
external: ['vue', 'lodash'],
},
sourcemap: true,
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
plugins: [
dts({
include: ['src'],
outDir: 'dist',
}),
],
});