修改了webpack的初始化过程,增加了注入
This commit is contained in:
parent
0ad9aa5e4a
commit
49454f9ee0
|
|
@ -81,7 +81,7 @@ const resolveModule = (resolveFn, filePath) => {
|
|||
return resolveFn(`${filePath}.js`);
|
||||
};
|
||||
|
||||
// config after eject: we're in ./config/
|
||||
// config after eject: we're in ./web
|
||||
module.exports = {
|
||||
dotenv: resolveApp('.env'),
|
||||
appPath: resolveApp('.'),
|
||||
|
|
|
|||
|
|
@ -205,15 +205,20 @@ module.exports = function (webpackEnv) {
|
|||
return loaders;
|
||||
};
|
||||
|
||||
// 读取编译配置
|
||||
const compilerConfigurationFile = path.join(paths.appRootPath, 'configuration', 'compiler.js');
|
||||
const projectConfigration = fs.existsSync(compilerConfigurationFile) && require(compilerConfigurationFile).webpack;
|
||||
|
||||
const getOakInclude = () => {
|
||||
return [
|
||||
/oak-domain/,
|
||||
/oak-external-sdk/,
|
||||
const result = [
|
||||
/oak-frontend-base/,
|
||||
/oak-general-business/,
|
||||
/oak-memory-tree-store/,
|
||||
/oak-common-aspect/,
|
||||
];
|
||||
if (projectConfigration && projectConfigration.extraOakModules) {
|
||||
result.push(...projectConfigration.extraOakModules);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
@ -369,7 +374,8 @@ module.exports = function (webpackEnv) {
|
|||
},
|
||||
},
|
||||
resolve: {
|
||||
fallback: {
|
||||
fallback: (() => {
|
||||
const defaultFb = {
|
||||
crypto: require.resolve('crypto-browserify'),
|
||||
buffer: require.resolve('safe-buffer'),
|
||||
stream: require.resolve('stream-browserify'),
|
||||
|
|
@ -380,7 +386,12 @@ module.exports = function (webpackEnv) {
|
|||
fs: false,
|
||||
net: false,
|
||||
tls: false,
|
||||
},
|
||||
}
|
||||
if (projectConfigration && projectConfigration.resolve && projectConfigration.resolve.fallback) {
|
||||
Object.assign(defaultFb, projectConfigration.resolve.fallback);
|
||||
}
|
||||
return defaultFb;
|
||||
})(),
|
||||
// This allows you to set a fallback for where webpack should look for modules.
|
||||
// We placed these paths second because we want `node_modules` to "win"
|
||||
// if there are any conflicts. This matches Node resolution mechanism.
|
||||
|
|
@ -397,7 +408,8 @@ module.exports = function (webpackEnv) {
|
|||
extensions: paths.moduleFileExtensions
|
||||
.map((ext) => `.${ext}`)
|
||||
.filter((ext) => useTypeScript || !ext.includes('ts')),
|
||||
alias: {
|
||||
alias: (() => {
|
||||
const defaultAlias = {
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
|
|
@ -407,14 +419,14 @@ module.exports = function (webpackEnv) {
|
|||
'scheduler/tracing': 'scheduler/tracing-profiling',
|
||||
}),
|
||||
...(modules.webpackAliases || {}),
|
||||
'@': paths.appSrc,
|
||||
'@project': paths.appRootSrc,
|
||||
'@oak-general-business': paths.oakGeneralBusinessPath,
|
||||
'@oak-frontend-base': paths.oakFrontendBasePath,
|
||||
'@oak-app-domain': paths.oakAppDomainPath,
|
||||
'bn.js': require.resolve('bn.js'),
|
||||
assert: require.resolve('browser-assert'),
|
||||
},
|
||||
};
|
||||
if (projectConfigration && projectConfigration.resolve && projectConfigration.resolve.alias) {
|
||||
Object.assign(defaultAlias, projectConfigration.resolve.alias);
|
||||
}
|
||||
return defaultAlias;
|
||||
})(),
|
||||
plugins: [
|
||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||
// This often causes confusion because we only process files within src/ with babel.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
// import { CompilerConfiguration } from 'oak-domain/lib/types/Configuration';
|
||||
const path = require('path');
|
||||
module.exports = {
|
||||
webpack: {
|
||||
resolve: {
|
||||
alias: {
|
||||
'@project': path.resolve('src'),
|
||||
'@oak-app-domain': path.resolve('src', 'oak-app-domain'),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
import { EntityDict } from '@project/oak-app-domain';
|
||||
import { Feature } from 'oak-frontend-base';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { AspectDict } from '../aspects/AspectDict';
|
||||
import { BackendRuntimeContext } from '@project/context/BackendRuntimeContext';
|
||||
import { FrontendRuntimeContext } from '@project/context/FrontendRuntimeContext';
|
||||
import { groupBy } from 'oak-domain/lib/utils/lodash';
|
||||
import { ContextMenuFactory } from 'oak-frontend-base/es/features/contextMenuFactory';
|
||||
import Console from './Console';
|
||||
|
||||
type GroupName = 'System';
|
||||
|
||||
type Groups = {
|
||||
icon: string;
|
||||
name: GroupName;
|
||||
}[];
|
||||
|
||||
interface IMenu<T extends keyof EntityDict> {
|
||||
name: string;
|
||||
icon: string;
|
||||
url: string;
|
||||
entity?: T;
|
||||
paths?: string[];
|
||||
action?: EntityDict[T]['Action'];
|
||||
parent?: GroupName;
|
||||
};
|
||||
|
||||
export interface OMenu {
|
||||
name: GroupName | string;
|
||||
icon: string;
|
||||
url?: string;
|
||||
children?: Array<OMenu>;
|
||||
};
|
||||
|
||||
|
||||
const groups: Groups = [
|
||||
{
|
||||
name: 'System', // 系统级别配置
|
||||
icon: 'setup_fill',
|
||||
},
|
||||
];
|
||||
|
||||
const menus: IMenu<keyof EntityDict>[] = [
|
||||
{
|
||||
name: 'Dashboard',
|
||||
icon: 'document',
|
||||
url: '',
|
||||
},
|
||||
{
|
||||
name: 'relationManage',
|
||||
icon: 'share',
|
||||
url: '/relation/entityList',
|
||||
parent: 'System',
|
||||
entity: 'relation',
|
||||
action: 'create',
|
||||
paths: [],
|
||||
},
|
||||
];
|
||||
|
||||
export default class Menu extends Feature {
|
||||
private contextMenuFactory: ContextMenuFactory<EntityDict,
|
||||
BackendRuntimeContext,
|
||||
FrontendRuntimeContext,
|
||||
AspectDict & CommonAspectDict<EntityDict, BackendRuntimeContext>>;
|
||||
private console: Console;
|
||||
private menus?: OMenu[];
|
||||
|
||||
constructor(
|
||||
contextMenuFactory: ContextMenuFactory<EntityDict,
|
||||
BackendRuntimeContext,
|
||||
FrontendRuntimeContext,
|
||||
AspectDict & CommonAspectDict<EntityDict, BackendRuntimeContext>>,
|
||||
console: Console
|
||||
) {
|
||||
super();
|
||||
this.contextMenuFactory = contextMenuFactory;
|
||||
this.contextMenuFactory.setMenus(menus);
|
||||
this.console = console;
|
||||
this.console.subscribe(
|
||||
() => {
|
||||
this.refreshMenus();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
refreshMenus() {
|
||||
const roomId = this.console.getRoomId();
|
||||
const menus = this.contextMenuFactory.getMenusByContext<IMenu<keyof EntityDict>>('room', roomId);
|
||||
const menuGroup = groupBy(menus, 'parent');
|
||||
this.menus = (menus as any[]).filter(ele => !ele.parent).concat(
|
||||
groups.map((ele) => {
|
||||
const { name, icon } = ele;
|
||||
const children = menuGroup[name];
|
||||
return {
|
||||
name,
|
||||
icon,
|
||||
children,
|
||||
};
|
||||
}).filter((ele) => !!ele.children)
|
||||
);
|
||||
this.publish();
|
||||
}
|
||||
|
||||
getMenus() {
|
||||
if (!this.menus) {
|
||||
this.refreshMenus();
|
||||
}
|
||||
return this.menus;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue