feat: 优化

This commit is contained in:
wanchun 2022-11-10 18:17:16 +08:00
commit 87738a2d05
30 changed files with 131 additions and 167 deletions

View File

@ -29,12 +29,9 @@
}
},
"include": [
"*.js",
".fes*.js",
"src/**/*",
"typings/**/*",
"config/**/*",
"src/.fes/configType.d.ts"
"*.js",
".fes*.js"
],
"exclude": [
"build",

View File

@ -33,8 +33,7 @@
".fes*.js",
"src/**/*",
"typings/**/*",
"config/**/*",
"src/.fes/configType.d.ts"
"config/**/*"
],
"exclude": [
"build",

View File

@ -3,7 +3,7 @@
"version": "3.0.0-beta.6",
"description": "@fesjs/builder-webpack",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"types": "types.d.ts",
"files": [
"lib",
"types.d.ts"
@ -66,4 +66,4 @@
"@fesjs/fes": "^3.0.0-beta.0",
"core-js": "^3.19.2"
}
}
}

View File

@ -1,6 +1,16 @@
import { Router, NavigationGuard } from 'vue-router';
import { Ref } from 'vue';
export function access(): {
hasAccess(accessId: string | number): Promise<boolean>;
isDataReady(): boolean;
setRole(roleId: string | Promise<string>): void;
setAccess(accessIds: Array<string | number> | Promise<Array<string | number>>): void;
getAccess(): string[];
};
export function useAccess(accessId: Array<string | number>): Ref<boolean>;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
access?:
@ -16,14 +26,4 @@ declare module '@fesjs/fes' {
unAccessHandler: (param: { router: Router } & NavigationGuard) => void;
};
}
export function access(): {
hasAccess(accessId: string | number): Promise<boolean>;
isDataReady(): boolean;
setRole(roleId: string | Promise<string>): void;
setAccess(accessIds: Array<string | number> | Promise<Array<string | number>>): void;
getAccess(): string[];
};
export function useAccess(accessId: Array<string | number>): Ref<boolean>;
}

View File

@ -14,12 +14,11 @@ interface EnumApi {
convert(name: string, _enum?: [] | object, option?: { keyName: string; valueName: string }): any;
}
export const enums: EnumApi;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
enums?: {
[key: string]: [string | number, string | number][];
} | false;
}
export const enums: EnumApi;
}

View File

@ -10,6 +10,7 @@ interface Menu {
children?: Menu[];
}
export const Page: Component;
declare module '@fesjs/fes' {
interface RouteMeta {
'keep-alive'?: boolean;
@ -61,5 +62,4 @@ declare module '@fesjs/fes' {
};
}
export const Page: Component;
}

View File

@ -1,5 +1,11 @@
import '@fesjs/fes';
export const locale: {
setLocale({ locale }: { locale: string }): void;
addLocale({ locale, messages }: { locale: string; messages: object }): void;
getAllLocales(): string[];
messages: Record<string, object>;
};
declare module '@fesjs/fes' {
interface PluginBuildConfig {
locale?:
@ -11,13 +17,4 @@ declare module '@fesjs/fes' {
}
| false;
}
// export * from 'vue-i18n';
export const locale: {
setLocale({ locale }: { locale: string }): void;
addLocale({ locale, messages }: { locale: string; messages: object }): void;
getAllLocales(): string[];
messages: Record<string, object>;
};
}

View File

@ -1,10 +1,9 @@
import '@fesjs/fes';
export function useModel(moduleId: string): any;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
model?: {} | false;
}
export function useModel(moduleId: string): any;
}

View File

@ -2,6 +2,7 @@ import type { Component } from 'vue';
import type { EditorLanguage } from 'monaco-editor-webpack-plugin/out/languages';
import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
export const MonacoEditor: Component;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
monacoEditor?: {
@ -12,6 +13,4 @@ declare module '@fesjs/fes' {
globalAPI: boolean;
} | false;
}
export const MonacoEditor: Component;
}

View File

@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
import { join } from 'path';
import { winPath } from '@fesjs/utils';
import { parseStore } from './helper';
import { name } from '../package.json';
const namespace = 'plugin-pinia';
@ -52,4 +53,8 @@ export default (api) => {
]);
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
api.addConfigType(() => ({
source: name,
}));
};

View File

@ -1,9 +1,8 @@
import type { Pinia } from 'pinia';
export const pinia: Pinia;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
pinia?: {} | false;
}
export const pinia: Pinia;
}

View File

@ -1,3 +1,4 @@
import { createMemoryHistory } from '@@/core/coreExports';
import qiankunRender, { clientRenderOptsStack, history as historyConfig } from './lifecycles';
@ -13,12 +14,9 @@ export function modifyClientRenderOpts(memo) {
};
}
export function modifyRoute(memo) {
export function modifyCreateHistory(memo) {
if (historyConfig.url) {
return {
...memo,
mode: 'memory'
}
return createMemoryHistory
}
return memo;
}

View File

@ -7,20 +7,18 @@ interface AppOption {
props: Record<string, any>;
}
declare module '@fesjs/fes' {
interface PluginBuildConfig {
qiankun?:
| {
main?: {
apps: AppOption[];
lifeCycles?: FrameworkLifeCycles<MicroApp>;
[key: string]: any;
};
micro?: {};
}
| false;
}
export const MicroApp: Component;
export const MicroAppWithMemoHistory: Component;
export interface PluginBuildConfig {
qiankun?:
| {
main?: {
apps: AppOption[];
lifeCycles?: FrameworkLifeCycles<MicroApp>;
[key: string]: any;
};
micro?: {};
}
| false;
}
export const MicroApp: Component;
export const MicroAppWithMemoHistory: Component;

View File

@ -13,6 +13,8 @@ interface RequestPluginOption {
}
}
export function request(url: string, data: null | Record<string, any>, options: AxiosRequestConfig & RequestPluginOption ): Promise<any>
export function useRequest(url: string, data: null | Record<string, any>, options: AxiosRequestConfig & RequestPluginOption ): {loadingRef: Ref<boolean>; errorRef: Ref<Error>; dataRef: Ref<any>}
declare module "@fesjs/fes" {
interface PluginRuntimeConfig {
request?: {
@ -22,6 +24,4 @@ declare module "@fesjs/fes" {
responseInterceptors?: ResponseInterceptor[];
} & AxiosRequestConfig;
}
export function request(url: string, data: null | Record<string, any>, options: AxiosRequestConfig & RequestPluginOption ): Promise<any>
export function useRequest(url: string, data: null | Record<string, any>, options: AxiosRequestConfig & RequestPluginOption ): {loadingRef: Ref<boolean>; errorRef: Ref<Error>; dataRef: Ref<any>}
}

View File

@ -1,4 +1,4 @@
import '@fesjs/fes';
declare module '@fesjs/fes' {
interface PluginBuildConfig {

View File

@ -1,4 +1,11 @@
import '@fesjs/fes';
export const MUTATION_TYPES: object;
export const ACTION_TYPES: object;
export const GETTER_TYPES: object;
export const store: object;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
vuex?:
@ -9,11 +16,4 @@ declare module '@fesjs/fes' {
| false;
}
export const MUTATION_TYPES: object;
export const ACTION_TYPES: object;
export const GETTER_TYPES: object;
export const store: object;
}

View File

@ -14,6 +14,8 @@ interface WatermarkParam {
zIndex: number;
timestamp: string;
}
export function createWatermark(param: WatermarkParam): void;
export function destroyWatermark(): void;
declare module '@fesjs/fes' {
interface PluginBuildConfig {
@ -21,7 +23,4 @@ declare module '@fesjs/fes' {
disable: boolean;
} | false;
}
export function createWatermark(param: WatermarkParam): void;
export function destroyWatermark(): void;
}

View File

@ -27,6 +27,8 @@ export default function (api) {
'render',
// 修改路由
'patchRoutes',
// 修改创建history API
'modifyCreateHistory',
// 修改路由配置
'modifyRoute',
// 生成router时触发

View File

@ -1,7 +1,7 @@
function importsToStr(imports) {
return imports.map((imp) => {
const { source } = imp;
return `import '${source}';`;
return `export * from '${source}';`;
});
}

View File

@ -311,6 +311,12 @@ export default function (api) {
const absExportsFilePath = join(namespace, 'routeExports.js');
const absRuntimeFilePath = join(namespace, 'runtime.js');
const historyType = {
history: 'createWebHistory',
hash: 'createWebHashHistory',
memory: 'createMemoryHistory',
};
api.onGenerateFiles(async () => {
const routesTpl = readFileSync(join(__dirname, 'template/routes.tpl'), 'utf-8');
const routes = await api.getRoutesJSON();
@ -328,7 +334,7 @@ export default function (api) {
content: Mustache.render(routeExportsTpl, {
runtimePath,
routerBase: api.config.router?.base,
routerMode: api.config.router.mode,
CREATE_HISTORY: historyType[api.config.router.mode] || 'createWebHashHistory',
}),
});

View File

@ -1,17 +1,18 @@
import { createRouter as createVueRouter, createWebHistory, createWebHashHistory, createMemoryHistory, ApplyPluginsType } from '{{{ runtimePath }}}';
import { createRouter as createVueRouter, {{{ CREATE_HISTORY }}}, ApplyPluginsType } from '{{{ runtimePath }}}';
import { plugin } from '../plugin';
const createHistoryMap = {
history: createWebHistory,
hash: createWebHashHistory,
memory: createMemoryHistory,
};
const ROUTER_BASE = '{{{ routerBase }}}';
const ROUTER_MODE = '{{{ routerMode }}}'
let router = null;
let history = null;
export const createRouter = (routes) => {
const createHistory = plugin.applyPlugins({
key: 'modifyCreateHistory',
type: ApplyPluginsType.modify,
args: {
base: ROUTER_BASE
},
initialValue: {{{ CREATE_HISTORY }}},
});
// 修改routes
plugin.applyPlugins({
key: 'patchRoutes',
@ -24,10 +25,10 @@ export const createRouter = (routes) => {
initialValue: {
base: ROUTER_BASE,
routes: routes,
mode: ROUTER_MODE
createHistory: createHistory
},
});
history = createHistoryMap[route.mode]?.(route.base);
history = route['createHistory']?.(route.base);
router = createVueRouter({
history,
routes: route.routes

View File

@ -1,5 +1,5 @@
import { Component, DefineComponent, App } from 'vue';
import { RouteRecordRaw, Router, RouterHistory } from 'vue-router';
import { RouteRecordRaw, Router, RouterHistory, createMemoryHistory, createWebHashHistory, createWebHistory } from 'vue-router';
// @ts-ignore
import { Plugin } from '@fesjs/runtime';
@ -19,10 +19,28 @@ interface ClientRenderOption {
type RenderFunc = () => Promise<App>
interface Route {
base: string; mode:string; routes: RouteRecordRaw[]
base: string;
mode:string;
createHistory: createMemoryHistory | createWebHashHistory | createWebHistory;
}
declare module "@fesjs/fes" {
export function getRouter(): Router;
export function getHistory(): RouterHistory;
export function destroyRouter(): void;
declare module '@fesjs/fes' {
interface PluginRuntimeConfig {
beforeRender?: (option: BeforeRenderConfig) => BeforeRenderConfig;
patchRoutes?: ({ routes }: { routes: RouteRecordRaw[] }) => void;
modifyRoute?: ({base, mode, createHistory }: Route) => Route;
modifyClientRenderOpts?: (option: ClientRenderOption) => ClientRenderOption;
rootContainer?: (component: DefineComponent, option: { routes: RouteRecordRaw[], plugin: Plugin }) => Component;
onAppCreated?: ({ app, routes }: { app: App, routes: RouteRecordRaw[] }) => void;
render?: (defaultRender: RenderFunc) => RenderFunc;
onRouterCreated?: ({ router }: { router: Router }) => void;
}
interface PluginBuildConfig {
alias?: Record<string, string>,
autoprefixer?: {
@ -84,18 +102,5 @@ declare module "@fesjs/fes" {
terserOptions?: object;
title?: string;
}
interface PluginRuntimeConfig {
beforeRender?: (option: BeforeRenderConfig) => BeforeRenderConfig;
patchRoutes?: ({ routes }: { routes: RouteRecordRaw[] }) => void;
modifyRoute?: ({base, mode, routes }: Route) => Route;
modifyClientRenderOpts?: (option: ClientRenderOption) => ClientRenderOption;
rootContainer?: (component: DefineComponent, option: { routes: RouteRecordRaw[], plugin: Plugin }) => Component;
onAppCreated?: ({ app, routes }: { app: App, routes: RouteRecordRaw[] }) => void;
render?: (defaultRender: RenderFunc) => RenderFunc;
onRouterCreated?: ({ router }: { router: Router }) => void;
}
export function getRouter(): Router;
export function getHistory(): RouterHistory;
export function destroyRouter(): void;
}

View File

@ -3,10 +3,7 @@
"outDir": "build/dist",
"module": "esnext",
"target": "esnext",
"lib": [
"esnext",
"dom"
],
"lib": ["esnext", "dom"],
"sourceMap": true,
"baseUrl": ".",
"jsx": "preserve",
@ -17,31 +14,18 @@
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"strict": true,
"paths": {
"@/*": [
"./src/*"
],
"@@/*": [
"./src/.fes/*"
]
"@/*": ["./src/*"],
"@@/*": ["./src/.fes/*"]
}
},
"include": [
"*.js",
".fes.js",
"src/**/*",
"typings/**/*",
"config/**/*",
"src/.fes/configType.d.ts"
".fes.js",
".fes.*.js"
],
"exclude": [
"build",
"dist",
"scripts",
"webpack",
"jest",
"node_modules"
]
}
"exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"]
}

View File

@ -1,6 +1,6 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
import { defineBuildConfig } from "@fesjs/fes";
export default {
export default defineBuildConfig({
define: {
__DEV__: false
},
@ -79,5 +79,5 @@ export default {
dynamicImport: true,
monacoEditor: {
languages: ['javascript', 'typescript', 'html', 'json']
}
};
},
});

View File

@ -1,3 +1,5 @@
import { defineBuildConfig } from "@fesjs/fes";
export default {
// define: {
// __DEV__: true

View File

@ -1,5 +1,4 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
import { defineBuildConfig } from "@fesjs/fes";
export default {
publicPath: 'https://gw.alipayobjects.com/'

View File

@ -24,15 +24,8 @@
},
"include": [
"src/**/*",
"tests/**/*",
"test/**/*",
"__test__/**/*",
"typings/**/*",
"config/**/*",
".eslintrc.js",
".stylelintrc.js",
".prettierrc.js",
"src/.fes/configType.d.ts"
".fes.js",
".fes.*.js"
],
"exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"]
}

View File

@ -3,10 +3,7 @@
"outDir": "build/dist",
"module": "esnext",
"target": "esnext",
"lib": [
"esnext",
"dom"
],
"lib": ["esnext", "dom"],
"sourceMap": true,
"baseUrl": ".",
"jsx": "preserve",
@ -17,31 +14,18 @@
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"strict": true,
"paths": {
"@/*": [
"./src/*"
],
"@@/*": [
"./src/.fes/*"
]
"@/*": ["./src/*"],
"@@/*": ["./src/.fes/*"]
}
},
"include": [
"*.js",
".fes.js",
"src/**/*",
"typings/**/*",
"config/**/*",
"src/.fes/configType.d.ts"
".fes.js",
".fes.*.js"
],
"exclude": [
"build",
"dist",
"scripts",
"webpack",
"jest",
"node_modules"
]
}
"exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"]
}

View File

@ -50,4 +50,4 @@
"node": "^10.12.0 || ^12.0.0 || >= 14.0.0"
},
"types": "types.d.ts"
}
}

View File

@ -1,5 +1,4 @@
// @ts-ignore
import '@@/configType';
export * from '@@/configType'
export * from '@fesjs/runtime';