Skip to content

Commit 820240e

Browse files
author
hubert
committed
feat: defintion a dev modules register
1 parent 7fc7d95 commit 820240e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/module-loader/src/register.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCurrentInstance, inject, isVue2 } from 'vue-demi';
2-
import { isArray, isPlainObject, isFunction, isUndef } from '@ace-util/core';
2+
import { isArray, isPlainObject, isFunction, isUndef, warn } from '@ace-util/core';
33
import { getLocation, compilePathRegex } from './utils/path';
44
import { debug } from './env';
55

@@ -315,6 +315,30 @@ export function registerComponents<T extends Record<string, string | { src: stri
315315
return useLoader;
316316
}
317317

318+
const DEV_MODULE_KEY = 'dev-modules';
319+
/**
320+
* Register dev modules from localStorage
321+
*/
322+
export function useDevModules(...args: [Lifecycles?, ModuleLoader?] | [ModuleLoader?]) {
323+
let loader: ModuleLoader | undefined, lifeCycles: Lifecycles | undefined;
324+
if (args[0] && (('setOptions' in args[0]) as any)) {
325+
loader = args[0] as ModuleLoader;
326+
} else {
327+
lifeCycles = args[0] as Lifecycles;
328+
loader = args[1];
329+
}
330+
const devModuleStr = localStorage.getItem(DEV_MODULE_KEY);
331+
let devModules = [];
332+
if (devModuleStr) {
333+
try {
334+
devModules = JSON.parse(devModuleStr);
335+
} catch {
336+
warn(process.env.NODE_ENV === 'production', `{DEV_MODULE_KEY} is not a valid JSON string`);
337+
}
338+
}
339+
return registerSubModules(devModules, lifeCycles)(loader);
340+
}
341+
318342
/**
319343
* Format module config from user input
320344
* @param config user input module config

0 commit comments

Comments
 (0)