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:
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": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"main": "./dist/index.umd.js",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.mjs",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./dist/index.js",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.umd.js",
|
"require": "./dist/index.cjs",
|
||||||
"types": "./dist/index.d.ts"
|
"types": "./dist/index.d.ts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"dev": "vitest dev"
|
"dev": "vitest dev",
|
||||||
|
"build": "unbuild"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@robonen/tsconfig": "workspace:*",
|
"@robonen/tsconfig": "workspace:*",
|
||||||
"@vue/test-utils": "catalog:",
|
"@vue/test-utils": "catalog:",
|
||||||
"jsdom": "catalog:",
|
"jsdom": "catalog:",
|
||||||
|
"unbuild": "catalog:",
|
||||||
"vitest": "catalog:"
|
"vitest": "catalog:"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -6,4 +6,3 @@ export * from './useMounted';
|
|||||||
export * from './useRenderCount';
|
export * from './useRenderCount';
|
||||||
export * from './useSupported';
|
export * from './useSupported';
|
||||||
export * from './useSyncRefs';
|
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:
|
jsdom:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 25.0.1
|
version: 25.0.1
|
||||||
|
unbuild:
|
||||||
|
specifier: 'catalog:'
|
||||||
|
version: 3.0.0-rc.8(typescript@5.4.4)
|
||||||
vitest:
|
vitest:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 2.1.2(@types/node@20.16.10)(jsdom@25.0.1)
|
version: 2.1.2(@types/node@20.16.10)(jsdom@25.0.1)
|
||||||
|
|||||||
Reference in New Issue
Block a user