Skip to content

Commit

Permalink
feat: support ssr
Browse files Browse the repository at this point in the history
feat: support ssr
  • Loading branch information
xiaohuoni authored Aug 25, 2021
2 parents 68db71f + 86802cc commit 4a36467
Show file tree
Hide file tree
Showing 33 changed files with 1,802 additions and 1,843 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"npm-run-all": "^4.1.5",
"open": "^8.0.2",
"prettier": "2.2.1",
"umi": "3.4.15",
"husky": "6.0.0",
"yorkie": "^2.0.0"
}
Expand Down
3 changes: 0 additions & 3 deletions packages/aconsole/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"umi": "3.x"
},
"dependencies": {
"@alitajs/inspx": "0.0.2",
"vconsole": "3.5.2"
Expand Down
6 changes: 6 additions & 0 deletions packages/alita/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
cjs: { type: 'babel', lazy: true },
esm: { type: 'rollup' },
disableTypeCheck: false,
extraExternals: ['@@/core/umiExports'],
};
1 change: 0 additions & 1 deletion packages/alita/index.esm.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/alita/index.js

This file was deleted.

10 changes: 4 additions & 6 deletions packages/alita/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
"name": "alita",
"version": "2.8.15",
"description": "alita",
"main": "index.js",
"module": "index.esm.js",
"main": "lib/index.js",
"module": "dist/index.esm.js",
"types": "types.d.ts",
"bin": {
"alita": "./bin/alita.js"
},
"files": [
"bin",
"lib",
"src",
"dist",
"types.d.ts",
"index.esm.js"
"types.d.ts"
],
"repository": {
"type": "git",
Expand All @@ -35,6 +33,6 @@
},
"dependencies": {
"@alitajs/umi-presets-alita": "2.8.15",
"umi": "3.4.15"
"umi": "3.5.17"
}
}
3 changes: 3 additions & 0 deletions packages/alita/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from 'umi';
// @ts-ignore
export * from '@@/core/umiExports';
25 changes: 25 additions & 0 deletions packages/alita/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"jsx": "preserve",
"skipLibCheck": true,
"allowJs": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"declaration": true
},
"exclude": [
"node_modules",
"dist",
"**/*.spec.ts",
"lib",
"fixtures",
"bin",
"examples"
]
}
3 changes: 0 additions & 3 deletions packages/hd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"license": "MIT",
"bugs": "http://github.com/alitajs/alita/issues",
"homepage": "https://github.com/alitajs/alita/tree/master/packages/hd#readme",
"peerDependencies": {
"umi": "3.x"
},
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/keep-alive/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export default (api: IApi) => {

api.addUmiExports(() => [
{
exportAll: true,
specifiers: ['KeepAliveLayout'],
source: `../${RELATIVE_MODEL}`,
},
{
exportAll: true,
specifiers: ['setLayoutInstance', 'getLayoutInstance', 'dropByCacheKey'],
source: `../${join(DIR_NAME, 'KeepAliveModel')}`,
},
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"access": "public"
},
"dependencies": {
"@alitajs/alita-layout": "2.4.7"
"@alitajs/alita-layout": "2.4.8"
}
}
1 change: 1 addition & 0 deletions packages/layout/src/exports.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getPageNavBar, setPageNavBar, setTabBarList, getTabBarList, layoutEmitter } from './layoutState';
19 changes: 17 additions & 2 deletions packages/layout/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { IApi, utils } from 'umi';
import { join } from 'path';
import { readFileSync } from 'fs';
import getLayoutContent from './utils/getLayoutContent';
import getLayout from './utils/getLayout';
import getModelContent from './utils/getModelContent';
const { Mustache } = utils;

const DIR_NAME = 'alita-layout';
const MODEL_NAME = 'layoutState';
Expand All @@ -27,10 +30,16 @@ export default (api: IApi) => {
api.addRuntimePluginKey(() => 'mobileLayout');

api.onGenerateFiles(() => {
api.writeTmpFile({
path: join(DIR_NAME, 'Layout.tsx'),
content: getLayout(),
});
api.writeTmpFile({
path: join(DIR_NAME, 'AlitaLayout.tsx'),
content: getLayoutContent(
utils.winPath(join(__dirname, './layout/index.js')),
utils.winPath(
join(api.paths.absTmpPath || '', DIR_NAME, 'Layout.tsx'),
),
!!api.userConfig.keepalive,
isMicroApp
),
Expand All @@ -39,6 +48,12 @@ export default (api: IApi) => {
path: RELATIVE_MODEL_PATH,
content: getModelContent(),
});
const exportsTpl = readFileSync(join(__dirname, 'exports.tpl'), 'utf-8');

api.writeTmpFile({
path: 'alita-layout/exports.ts',
content: exportsTpl,
});
});

api.modifyRoutes((routes) => [
Expand All @@ -54,7 +69,7 @@ export default (api: IApi) => {
api.addUmiExports(() => [
{
exportAll: true,
source: `../${RELATIVE_MODEL}`,
source: '../alita-layout/exports',
},
{
exportAll: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useEffect, useState } from 'react';
export default (
) => `import React, { useEffect, useState } from 'react';
import { Location, LocationState } from 'history';
// @ts-ignore
// eslint-disable-next-line
import {
getPageNavBar,
KeepAliveLayout,
getTabBarList,
layoutEmitter,
request,
RequestMethodInUmi
} from 'umi';
} from '@@/core/umiExports';
import AlitaLayout, {
AlitaLayoutProps,
Expand Down Expand Up @@ -93,7 +94,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
prevPathName = props.location.pathname;
}, 10);
}, [props.location.pathname]);
layoutEmitter.useSubscription(() => {
layoutEmitter?.useSubscription?.(() => {
setPageNavBar(getPageNavBar());
setTabBarList(getTabBarList());
});
Expand All @@ -117,3 +118,4 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
};
export default BasicLayout;
`;
1 change: 0 additions & 1 deletion packages/main-path/README.md

This file was deleted.

30 changes: 0 additions & 30 deletions packages/main-path/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/plugin-dva/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"license": "MIT",
"bugs": "http://github.com/umijs/plugins/issues",
"homepage": "https://github.com/umijs/plugins/tree/master/packages/plugin-dva#readme",
"peerDependencies": {
"umi": "3.x"
},
"publishConfig": {
"access": "public"
},
Expand Down
29 changes: 15 additions & 14 deletions packages/plugin-dva/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ app.model({ namespace: '${basename(path, extname(path))}', ...Model${lodash.uppe
dvaHeadExport: api.config.dva?.disableModelsReExport
? ``
: models
.map((path) => {
// prettier-ignore
return `export * from '${winPath(path)}';`;
})
.join('\r\n'),
.map((path) => {
// prettier-ignore
// export type { IndexModelState } from '/Users/xiaohuoni/next-alita-app/src/models';
return `export type { ${basename(path, extname(path)).toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase())}ModelState } from '${winPath(path)}';`;
})
.join('\r\n'),
dvaLoadingModels: models
.map((path) => {
// prettier-ignore
Expand Down Expand Up @@ -236,15 +237,15 @@ app.model({ namespace: '${basename(path, extname(path))}', ...Model${lodash.uppe
api.addUmiExports(() =>
hasModels
? [
{
exportAll: true,
source: '../plugin-dva/exports',
},
{
exportAll: true,
source: '../plugin-dva/connect',
},
]
{
exportAll: true,
source: '../plugin-dva/exports',
},
{
exportAll: true,
source: '../plugin-dva/connect',
},
]
: [],
);

Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"@ant-design/pro-layout": "^5.0.0",
"@umijs/plugin-initial-state": "2.x",
"@umijs/plugin-locale": "0.x",
"@umijs/plugin-model": "2.x",
"umi": "3.x"
"@umijs/plugin-model": "2.x"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 0 additions & 1 deletion packages/retain-log/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions packages/retain-log/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/router/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions packages/router/package.json

This file was deleted.

24 changes: 0 additions & 24 deletions packages/router/src/index.ts

This file was deleted.

Loading

0 comments on commit 4a36467

Please sign in to comment.