mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 02:44:45 +00:00
feat(packages/vue): add build config
This commit is contained in:
10
packages/vue/build.config.ts
Normal file
10
packages/vue/build.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { defineBuildConfig } from 'unbuild';
|
||||
|
||||
export default defineBuildConfig({
|
||||
externals: ['vue'],
|
||||
rollup: {
|
||||
esbuild: {
|
||||
// minify: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -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": {
|
||||
|
||||
@@ -6,4 +6,3 @@ export * from './useMounted';
|
||||
export * from './useRenderCount';
|
||||
export * from './useSupported';
|
||||
export * from './useSyncRefs';
|
||||
export * from './useToggle';
|
||||
|
||||
38
packages/vue/src/composables/tryOnMounted/index.ts
Normal file
38
packages/vue/src/composables/tryOnMounted/index.ts
Normal 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);
|
||||
}
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -110,6 +110,9 @@ importers:
|
||||
jsdom:
|
||||
specifier: 'catalog:'
|
||||
version: 25.0.1
|
||||
unbuild:
|
||||
specifier: 'catalog:'
|
||||
version: 3.0.0-rc.8(typescript@5.4.4)
|
||||
vitest:
|
||||
specifier: 'catalog:'
|
||||
version: 2.1.2(@types/node@20.16.10)(jsdom@25.0.1)
|
||||
|
||||
Reference in New Issue
Block a user