loader
ee-core:v2.0.3
# 介绍
加载器模块。开发者自己维护的js模块/文件,需要被执行或者在 controller、service、jobs、preload等业务层被调用的时候,可能有路径、加密等问题。使用加载器可以避免它们。
# 使用方法
const Loader = require('ee-core/loader');
# API列表
# loadJsFile(filepath)
- filepath [String] - 文件的绝对路径
加载js文件,返回一个模块。
# execJsFile(filepath, ...inject)
- filepath [String] - 文件的绝对路径
- inject [] - 注入的参数
加载并运行js文件,返回结果。如果文件是class将被实例化,如果是Function将被调用。
# resolveModule(filepath)
- filepath [String] - 文件路径
返回文件的绝对路径。
# requireModule(filepath, type = '')
- filepath [String] - 文件路径
- type [String] - 类型
加载模块 (子进程中使用)
const Loader = require('ee-core/loader');
// 相当于加载 ./electron/jobs/example/hello
const Hello = Loader.requireModule('./jobs/example/hello');
const Hello = Loader.requireModule('./example/hello', 'jobs');
// 相当于加载 ./electron/library/example/hello
const Hello = Loader.requireModule('./library/example/hello');
const Hello = Loader.requireModule('./example/hello', 'library');
# requireJobsModule(filepath)
- filepath [String] - 文件路径
加载模块 (子进程中使用)
const Loader = require('ee-core/loader');
// 相当于加载 ./electron/jobs/example/hello
const Hello = Loader.requireJobsModule('./example/hello');
上次更新: 2025/01/21, 10:05:58