1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

feat(packages/vue): add build config

This commit is contained in:
2024-10-06 07:31:29 +07:00
parent d48e6469a3
commit 4bbc3b45a2
5 changed files with 58 additions and 6 deletions

View File

@@ -0,0 +1,10 @@
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
externals: ['vue'],
rollup: {
esbuild: {
// minify: true,
},
},
});

View File

@@ -19,24 +19,26 @@
"files": [
"dist"
],
"main": "./dist/index.umd.js",
"module": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.js",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"test": "vitest run",
"dev": "vitest dev"
"dev": "vitest dev",
"build": "unbuild"
},
"devDependencies": {
"@robonen/tsconfig": "workspace:*",
"@vue/test-utils": "catalog:",
"jsdom": "catalog:",
"unbuild": "catalog:",
"vitest": "catalog:"
},
"dependencies": {

View File

@@ -6,4 +6,3 @@ export * from './useMounted';
export * from './useRenderCount';
export * from './useSupported';
export * from './useSyncRefs';
export * from './useToggle';

View File

@@ -0,0 +1,38 @@
import { onMounted, nextTick, type ComponentInternalInstance } from 'vue';
import { getLifeCycleTarger } from '../../utils';
export interface TryOnMountedOptions {
sync?: boolean;
target?: ComponentInternalInstance;
}
/**
* @name tryOnMounted
* @category Components
* @description Calls a function if it's inside a component lifecycle hook, otherwise just calls it
*
* @param {Function} fn The function to call
* @param {TryOnMountedOptions} [options={}] The options for the try on mounted function
* @returns {void}
*
* @example
* tryOnMounted(() => console.log('Mounted!'));
*
* @example
* tryOnMounted(() => console.log('Mounted!'), { sync: false });
*/
export function tryOnMounted(fn: () => void, options: TryOnMountedOptions = {}) {
const instance = getLifeCycleTarger();
const {
sync = true,
target,
} = options;
if (instance)
onMounted(fn, target);
else if (sync)
fn();
else
nextTick(fn);
}