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": [ "include": [
"*.js",
".fes*.js",
"src/**/*", "src/**/*",
"typings/**/*", "*.js",
"config/**/*", ".fes*.js"
"src/.fes/configType.d.ts"
], ],
"exclude": [ "exclude": [
"build", "build",

View File

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

View File

@ -3,7 +3,7 @@
"version": "3.0.0-beta.6", "version": "3.0.0-beta.6",
"description": "@fesjs/builder-webpack", "description": "@fesjs/builder-webpack",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "types.d.ts",
"files": [ "files": [
"lib", "lib",
"types.d.ts" "types.d.ts"

View File

@ -1,6 +1,16 @@
import { Router, NavigationGuard } from 'vue-router'; import { Router, NavigationGuard } from 'vue-router';
import { Ref } from 'vue'; 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' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
access?: access?:
@ -16,14 +26,4 @@ declare module '@fesjs/fes' {
unAccessHandler: (param: { router: Router } & NavigationGuard) => void; 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; convert(name: string, _enum?: [] | object, option?: { keyName: string; valueName: string }): any;
} }
export const enums: EnumApi;
declare module '@fesjs/fes' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
enums?: { enums?: {
[key: string]: [string | number, string | number][]; [key: string]: [string | number, string | number][];
} | false; } | false;
} }
export const enums: EnumApi;
} }

View File

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

View File

@ -1,5 +1,11 @@
import '@fesjs/fes'; 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' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
locale?: locale?:
@ -11,13 +17,4 @@ declare module '@fesjs/fes' {
} }
| false; | 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'; import '@fesjs/fes';
export function useModel(moduleId: string): any;
declare module '@fesjs/fes' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
model?: {} | false; 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 { EditorLanguage } from 'monaco-editor-webpack-plugin/out/languages';
import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features'; import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
export const MonacoEditor: Component;
declare module '@fesjs/fes' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
monacoEditor?: { monacoEditor?: {
@ -12,6 +13,4 @@ declare module '@fesjs/fes' {
globalAPI: boolean; globalAPI: boolean;
} | false; } | false;
} }
export const MonacoEditor: Component;
} }

View File

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

View File

@ -1,9 +1,8 @@
import type { Pinia } from 'pinia'; import type { Pinia } from 'pinia';
export const pinia: Pinia;
declare module '@fesjs/fes' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
pinia?: {} | false; 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'; 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) { if (historyConfig.url) {
return { return createMemoryHistory
...memo,
mode: 'memory'
}
} }
return memo; return memo;
} }

View File

@ -7,8 +7,7 @@ interface AppOption {
props: Record<string, any>; props: Record<string, any>;
} }
declare module '@fesjs/fes' { export interface PluginBuildConfig {
interface PluginBuildConfig {
qiankun?: qiankun?:
| { | {
main?: { main?: {
@ -23,4 +22,3 @@ declare module '@fesjs/fes' {
export const MicroApp: Component; export const MicroApp: Component;
export const MicroAppWithMemoHistory: 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" { declare module "@fesjs/fes" {
interface PluginRuntimeConfig { interface PluginRuntimeConfig {
request?: { request?: {
@ -22,6 +24,4 @@ declare module "@fesjs/fes" {
responseInterceptors?: ResponseInterceptor[]; responseInterceptors?: ResponseInterceptor[];
} & AxiosRequestConfig; } & 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' { declare module '@fesjs/fes' {
interface PluginBuildConfig { 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' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
vuex?: vuex?:
@ -9,11 +16,4 @@ declare module '@fesjs/fes' {
| false; | 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; zIndex: number;
timestamp: string; timestamp: string;
} }
export function createWatermark(param: WatermarkParam): void;
export function destroyWatermark(): void;
declare module '@fesjs/fes' { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
@ -21,7 +23,4 @@ declare module '@fesjs/fes' {
disable: boolean; disable: boolean;
} | false; } | false;
} }
export function createWatermark(param: WatermarkParam): void;
export function destroyWatermark(): void;
} }

View File

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

View File

@ -1,7 +1,7 @@
function importsToStr(imports) { function importsToStr(imports) {
return imports.map((imp) => { return imports.map((imp) => {
const { source } = 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 absExportsFilePath = join(namespace, 'routeExports.js');
const absRuntimeFilePath = join(namespace, 'runtime.js'); const absRuntimeFilePath = join(namespace, 'runtime.js');
const historyType = {
history: 'createWebHistory',
hash: 'createWebHashHistory',
memory: 'createMemoryHistory',
};
api.onGenerateFiles(async () => { api.onGenerateFiles(async () => {
const routesTpl = readFileSync(join(__dirname, 'template/routes.tpl'), 'utf-8'); const routesTpl = readFileSync(join(__dirname, 'template/routes.tpl'), 'utf-8');
const routes = await api.getRoutesJSON(); const routes = await api.getRoutesJSON();
@ -328,7 +334,7 @@ export default function (api) {
content: Mustache.render(routeExportsTpl, { content: Mustache.render(routeExportsTpl, {
runtimePath, runtimePath,
routerBase: api.config.router?.base, 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'; import { plugin } from '../plugin';
const createHistoryMap = {
history: createWebHistory,
hash: createWebHashHistory,
memory: createMemoryHistory,
};
const ROUTER_BASE = '{{{ routerBase }}}'; const ROUTER_BASE = '{{{ routerBase }}}';
const ROUTER_MODE = '{{{ routerMode }}}'
let router = null; let router = null;
let history = null; let history = null;
export const createRouter = (routes) => { export const createRouter = (routes) => {
const createHistory = plugin.applyPlugins({
key: 'modifyCreateHistory',
type: ApplyPluginsType.modify,
args: {
base: ROUTER_BASE
},
initialValue: {{{ CREATE_HISTORY }}},
});
// 修改routes // 修改routes
plugin.applyPlugins({ plugin.applyPlugins({
key: 'patchRoutes', key: 'patchRoutes',
@ -24,10 +25,10 @@ export const createRouter = (routes) => {
initialValue: { initialValue: {
base: ROUTER_BASE, base: ROUTER_BASE,
routes: routes, routes: routes,
mode: ROUTER_MODE createHistory: createHistory
}, },
}); });
history = createHistoryMap[route.mode]?.(route.base); history = route['createHistory']?.(route.base);
router = createVueRouter({ router = createVueRouter({
history, history,
routes: route.routes routes: route.routes

View File

@ -1,5 +1,5 @@
import { Component, DefineComponent, App } from 'vue'; 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 // @ts-ignore
import { Plugin } from '@fesjs/runtime'; import { Plugin } from '@fesjs/runtime';
@ -19,10 +19,28 @@ interface ClientRenderOption {
type RenderFunc = () => Promise<App> type RenderFunc = () => Promise<App>
interface Route { interface Route {
base: string; mode:string; routes: RouteRecordRaw[] base: string;
mode:string;
createHistory: createMemoryHistory | createWebHashHistory | createWebHistory;
}
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;
} }
declare module "@fesjs/fes" {
interface PluginBuildConfig { interface PluginBuildConfig {
alias?: Record<string, string>, alias?: Record<string, string>,
autoprefixer?: { autoprefixer?: {
@ -84,18 +102,5 @@ declare module "@fesjs/fes" {
terserOptions?: object; terserOptions?: object;
title?: string; 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", "outDir": "build/dist",
"module": "esnext", "module": "esnext",
"target": "esnext", "target": "esnext",
"lib": [ "lib": ["esnext", "dom"],
"esnext",
"dom"
],
"sourceMap": true, "sourceMap": true,
"baseUrl": ".", "baseUrl": ".",
"jsx": "preserve", "jsx": "preserve",
@ -17,31 +14,18 @@
"suppressImplicitAnyIndexErrors": true, "suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"allowJs": true, "allowJs": true,
"skipLibCheck": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"strict": true, "strict": true,
"paths": { "paths": {
"@/*": [ "@/*": ["./src/*"],
"./src/*" "@@/*": ["./src/.fes/*"]
],
"@@/*": [
"./src/.fes/*"
]
} }
}, },
"include": [ "include": [
"*.js",
".fes.js",
"src/**/*", "src/**/*",
"typings/**/*", ".fes.js",
"config/**/*", ".fes.*.js"
"src/.fes/configType.d.ts"
], ],
"exclude": [ "exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"]
"build",
"dist",
"scripts",
"webpack",
"jest",
"node_modules"
]
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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