Skip to content

Commit 078aba6

Browse files
authored
feat: plugin exclude routes
Feat plugin exclude routes
2 parents ea5a355 + fbba2cc commit 078aba6

File tree

27 files changed

+524
-13
lines changed

27 files changed

+524
-13
lines changed

.changeset/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@examples/aclass",
1919
"@examples/alita2",
2020
"@examples/boilerplate",
21+
"@examples/extends-app",
2122
"@examples/helmet",
2223
"@examples/state",
2324
"@examples/legacy",

.changeset/smart-apes-cheat.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@alita/plugin-extends-app': patch
3+
'@alita/plugins': patch
4+
'alita': patch
5+
---
6+
7+
feat: add plugin extends app

examples/extends-app/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.env.local
2+
/.umirc.local.ts
3+
/.umirc.local.js
4+
/config/config.local.ts
5+
/config/config.local.js
6+
/src/.umi
7+
/.umi

examples/extends-app/config/config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineConfig } from 'alita';
2+
3+
export default defineConfig({
4+
appType: 'h5',
5+
keepalive: [/./],
6+
extendsApp: {
7+
root: 'root',
8+
},
9+
plugins: ['@alita/plugin-extends-app'],
10+
mobileLayout: true,
11+
legacyBuild: false,
12+
// mainPath:'users',
13+
mfsu: {},
14+
hash: false,
15+
});

examples/extends-app/mock/app.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
'/api/hello': {
3+
text: 'Alita',
4+
},
5+
};

examples/extends-app/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@examples/extends-app",
3+
"private": true,
4+
"scripts": {
5+
"dev": "alita dev",
6+
"build": "alita build",
7+
"plugin": "alita plugin list",
8+
"start": "npm run dev"
9+
},
10+
"dependencies": {
11+
"@alita/flow": "workspace:*",
12+
"@alita/plugin-extends-app": "workspace:*",
13+
"ahooks": "^3.0.8",
14+
"alita": "workspace:*",
15+
"antd-mobile": "^5.10.0"
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.title {
2+
font-size: 30px;
3+
}
4+
.adm-button{
5+
font-size: 30px
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Button } from 'antd-mobile';
2+
import React, { useState } from 'react';
3+
import styles from './index.less';
4+
export default () => {
5+
const [count, setCount] = useState(0);
6+
return (
7+
<div className={styles['adm-button']}>
8+
exclude routes hello
9+
<Button
10+
type="button"
11+
color="primary"
12+
fill="solid"
13+
block
14+
size="large"
15+
onClick={() => setCount(count + 1)}
16+
>
17+
点我计数加1 {count}
18+
</Button>
19+
</div>
20+
);
21+
};

examples/extends-app/src/app.tsx

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import HomeGary from '@/assets/demoIcon/home.png';
2+
import HomeBlue from '@/assets/demoIcon/home1.png';
3+
import ListGary from '@/assets/demoIcon/list.png';
4+
import ListBlue from '@/assets/demoIcon/list1.png';
5+
import type {
6+
NavBarListItem,
7+
NavBarProps,
8+
TabBarListItem,
9+
TabBarProps,
10+
TitleListItem,
11+
} from 'alita';
12+
13+
export const request = {
14+
prefix: '/api',
15+
method: 'get',
16+
errorHandler: (error) => {
17+
// 集中处理错误
18+
console.log(11111111);
19+
console.log(error);
20+
},
21+
};
22+
23+
const titleList: TitleListItem[] = [
24+
{
25+
pagePath: '/',
26+
title: '首页',
27+
},
28+
{
29+
pagePath: '/hello',
30+
title: 'Hi',
31+
},
32+
];
33+
const navList: NavBarListItem[] = [
34+
{
35+
pagePath: '/',
36+
navBar: {
37+
pageBackground: '#fff',
38+
},
39+
},
40+
{
41+
pagePath: '/hello',
42+
navBar: {
43+
pageBackground: '#e5e5e5',
44+
},
45+
},
46+
];
47+
const navBar: NavBarProps = {
48+
navList,
49+
fixed: false,
50+
onLeftClick: () => {
51+
// router.goBack();
52+
},
53+
};
54+
const tabList: TabBarListItem[] = [
55+
{
56+
pagePath: '/',
57+
text: '首页',
58+
iconPath: HomeGary,
59+
selectedIconPath: HomeBlue,
60+
title: '首页',
61+
iconSize: '',
62+
badge: '',
63+
},
64+
{
65+
pagePath: '/hello',
66+
text: 'Hi',
67+
iconPath: ListGary,
68+
selectedIconPath: ListBlue,
69+
title: 'Hi',
70+
iconSize: '',
71+
badge: '',
72+
},
73+
];
74+
75+
const tabBar: TabBarProps = {
76+
color: `#999999`,
77+
selectedColor: '#00A0FF',
78+
borderStyle: 'white',
79+
position: 'bottom',
80+
list: tabList,
81+
};
82+
83+
export const mobileLayout = {
84+
documentTitle: '默认标题',
85+
navBar,
86+
tabBar,
87+
titleList,
88+
};
667 Bytes
Loading
590 Bytes
Loading
157 Bytes
Loading
160 Bytes
Loading
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { query } from '@/services/api';
2+
import type { DvaModel } from 'alita';
3+
4+
export interface IndexModelState {
5+
name: string;
6+
}
7+
8+
const IndexModel: DvaModel<IndexModelState> = {
9+
namespace: 'index',
10+
11+
state: {
12+
name: 'Hello Alita',
13+
},
14+
15+
effects: {
16+
*query({ payload }, { call, put }) {
17+
const data = yield call(query, payload);
18+
yield put({
19+
type: 'save',
20+
payload: { name: data.text },
21+
});
22+
},
23+
},
24+
reducers: {
25+
save(state, action) {
26+
return {
27+
...state,
28+
...action.payload,
29+
};
30+
},
31+
},
32+
};
33+
34+
export default IndexModel;
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useState } from 'react';
2+
3+
export default function () {
4+
const [todos, setTodos] = useState(['foo', 'bar']);
5+
return {
6+
todos,
7+
setTodos,
8+
};
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a {
2+
color: green;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.title {
2+
font-size: 30px;
3+
}
4+
.adm-button{
5+
font-size: 30px
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Button } from 'antd-mobile';
2+
import React, { useState } from 'react';
3+
import styles from './index.less';
4+
export default () => {
5+
const [count, setCount] = useState(0);
6+
return (
7+
<div className={styles['adm-button']}>
8+
Hello Alita
9+
<Button
10+
type="button"
11+
color="primary"
12+
fill="solid"
13+
block
14+
size="large"
15+
onClick={() => setCount(count + 1)}
16+
>
17+
点我计数加1 {count}
18+
</Button>
19+
</div>
20+
);
21+
};
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { request } from '@@/plugin-request';
2+
3+
export async function query(): Promise<any> {
4+
return request('/hello');
5+
}

examples/extends-app/tsconfig.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"baseUrl": "./",
5+
"outDir": "dist",
6+
"sourceMap": true,
7+
"jsx": "react",
8+
"declaration": false,
9+
"module": "esnext",
10+
"moduleResolution": "node",
11+
"emitDecoratorMetadata": true,
12+
"experimentalDecorators": true,
13+
"importHelpers": true,
14+
"target": "es2017",
15+
"typeRoots": ["node_modules/@types"],
16+
"lib": ["es2018", "dom"],
17+
"allowSyntheticDefaultImports": true,
18+
"rootDirs": ["/src", "/root", "/test", "/mock", "./typings"],
19+
"forceConsistentCasingInFileNames": true,
20+
"noImplicitReturns": true,
21+
"suppressImplicitAnyIndexErrors": true,
22+
"noUnusedLocals": true,
23+
"allowJs": true,
24+
"strict": true,
25+
"paths": {
26+
"@/*": ["./src/*"],
27+
"@@/*": ["./src/.umi/*"],
28+
"alita": ["./src/.umi/*"]
29+
}
30+
}
31+
}

examples/extends-app/typings.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
declare module '*.css';
2+
declare module '*.less';
3+
declare module '*.scss';
4+
declare module '*.sass';
5+
declare module '*.svg';
6+
declare module '*.png';
7+
declare module '*.jpg';
8+
declare module '*.jpeg';
9+
declare module '*.gif';
10+
declare module '*.bmp';
11+
declare module '*.tiff';
12+
declare module '*.json';
13+

packages/alita/src/features/compatibleMako.ts

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { IApi } from 'umi';
2-
import { dirname } from 'path';
2+
import { dirname, join, resolve } from 'path';
3+
import { fsExtra, glob } from '@umijs/utils';
4+
import { copyFileSync, statSync } from 'fs';
35

46
export default (api: IApi) => {
57
// 强制关闭
@@ -17,6 +19,43 @@ export default (api: IApi) => {
1719
);
1820
}
1921
}
22+
if (api.userConfig.copy) {
23+
const copy = [
24+
{
25+
from: join(
26+
dirname(require.resolve('pdfjs-dist/package.json')),
27+
'cmaps',
28+
),
29+
to: 'build/static/cmaps/',
30+
},
31+
];
32+
const copyDirectory = (opts: any) => {
33+
const files = glob.sync('**/*', {
34+
cwd: opts.path,
35+
dot: true,
36+
});
37+
files.forEach((file: any) => {
38+
const absFile = join(opts.path, file);
39+
if (statSync(absFile).isDirectory()) return;
40+
const absTarget = join(opts.target, file);
41+
fsExtra.mkdirpSync(dirname(absTarget));
42+
copyFileSync(absFile, absTarget);
43+
});
44+
};
45+
46+
copy.forEach((file) => {
47+
const sourcePath = resolve(file.from);
48+
const destinationPath = resolve(
49+
api.userConfig.outputPath || api.paths.absOutputPath,
50+
file.to,
51+
);
52+
copyDirectory({
53+
path: sourcePath,
54+
target: destinationPath,
55+
});
56+
});
57+
}
58+
memo.copy = [];
2059
return memo;
2160
});
2261
}

packages/plugin-extends-app/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @alita/plugin-exclude-pages
2+
3+
See our website [alitajs](https://alitajs.com) for more information.

0 commit comments

Comments
 (0)