Skip to content

Commit

Permalink
feat: plugin exclude routes
Browse files Browse the repository at this point in the history
Feat plugin exclude routes
  • Loading branch information
xiaohuoni authored Nov 5, 2024
2 parents ea5a355 + fbba2cc commit 078aba6
Show file tree
Hide file tree
Showing 27 changed files with 524 additions and 13 deletions.
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@examples/aclass",
"@examples/alita2",
"@examples/boilerplate",
"@examples/extends-app",
"@examples/helmet",
"@examples/state",
"@examples/legacy",
Expand Down
7 changes: 7 additions & 0 deletions .changeset/smart-apes-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@alita/plugin-extends-app': patch
'@alita/plugins': patch
'alita': patch
---

feat: add plugin extends app
7 changes: 7 additions & 0 deletions examples/extends-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.env.local
/.umirc.local.ts
/.umirc.local.js
/config/config.local.ts
/config/config.local.js
/src/.umi
/.umi
15 changes: 15 additions & 0 deletions examples/extends-app/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'alita';

export default defineConfig({
appType: 'h5',
keepalive: [/./],
extendsApp: {
root: 'root',
},
plugins: ['@alita/plugin-extends-app'],
mobileLayout: true,
legacyBuild: false,
// mainPath:'users',
mfsu: {},
hash: false,
});
5 changes: 5 additions & 0 deletions examples/extends-app/mock/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
'/api/hello': {
text: 'Alita',
},
};
17 changes: 17 additions & 0 deletions examples/extends-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@examples/extends-app",
"private": true,
"scripts": {
"dev": "alita dev",
"build": "alita build",
"plugin": "alita plugin list",
"start": "npm run dev"
},
"dependencies": {
"@alita/flow": "workspace:*",
"@alita/plugin-extends-app": "workspace:*",
"ahooks": "^3.0.8",
"alita": "workspace:*",
"antd-mobile": "^5.10.0"
}
}
6 changes: 6 additions & 0 deletions examples/extends-app/root/pages/index/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.title {
font-size: 30px;
}
.adm-button{
font-size: 30px
}
21 changes: 21 additions & 0 deletions examples/extends-app/root/pages/index/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Button } from 'antd-mobile';
import React, { useState } from 'react';
import styles from './index.less';
export default () => {
const [count, setCount] = useState(0);
return (
<div className={styles['adm-button']}>
exclude routes hello
<Button
type="button"
color="primary"
fill="solid"
block
size="large"
onClick={() => setCount(count + 1)}
>
点我计数加1 {count}
</Button>
</div>
);
};
88 changes: 88 additions & 0 deletions examples/extends-app/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import HomeGary from '@/assets/demoIcon/home.png';
import HomeBlue from '@/assets/demoIcon/home1.png';
import ListGary from '@/assets/demoIcon/list.png';
import ListBlue from '@/assets/demoIcon/list1.png';
import type {
NavBarListItem,
NavBarProps,
TabBarListItem,
TabBarProps,
TitleListItem,
} from 'alita';

export const request = {
prefix: '/api',
method: 'get',
errorHandler: (error) => {
// 集中处理错误
console.log(11111111);
console.log(error);
},
};

const titleList: TitleListItem[] = [
{
pagePath: '/',
title: '首页',
},
{
pagePath: '/hello',
title: 'Hi',
},
];
const navList: NavBarListItem[] = [
{
pagePath: '/',
navBar: {
pageBackground: '#fff',
},
},
{
pagePath: '/hello',
navBar: {
pageBackground: '#e5e5e5',
},
},
];
const navBar: NavBarProps = {
navList,
fixed: false,
onLeftClick: () => {
// router.goBack();
},
};
const tabList: TabBarListItem[] = [
{
pagePath: '/',
text: '首页',
iconPath: HomeGary,
selectedIconPath: HomeBlue,
title: '首页',
iconSize: '',
badge: '',
},
{
pagePath: '/hello',
text: 'Hi',
iconPath: ListGary,
selectedIconPath: ListBlue,
title: 'Hi',
iconSize: '',
badge: '',
},
];

const tabBar: TabBarProps = {
color: `#999999`,
selectedColor: '#00A0FF',
borderStyle: 'white',
position: 'bottom',
list: tabList,
};

export const mobileLayout = {
documentTitle: '默认标题',
navBar,
tabBar,
titleList,
};
Binary file added examples/extends-app/src/assets/demoIcon/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/extends-app/src/assets/demoIcon/home1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/extends-app/src/assets/demoIcon/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/extends-app/src/assets/demoIcon/list1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions examples/extends-app/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { query } from '@/services/api';
import type { DvaModel } from 'alita';

export interface IndexModelState {
name: string;
}

const IndexModel: DvaModel<IndexModelState> = {
namespace: 'index',

state: {
name: 'Hello Alita',
},

effects: {
*query({ payload }, { call, put }) {
const data = yield call(query, payload);
yield put({
type: 'save',
payload: { name: data.text },
});
},
},
reducers: {
save(state, action) {
return {
...state,
...action.payload,
};
},
},
};

export default IndexModel;
9 changes: 9 additions & 0 deletions examples/extends-app/src/models/todo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useState } from 'react';

export default function () {
const [todos, setTodos] = useState(['foo', 'bar']);
return {
todos,
setTodos,
};
}
3 changes: 3 additions & 0 deletions examples/extends-app/src/pages/global.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: green;
}
6 changes: 6 additions & 0 deletions examples/extends-app/src/pages/index/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.title {
font-size: 30px;
}
.adm-button{
font-size: 30px
}
21 changes: 21 additions & 0 deletions examples/extends-app/src/pages/index/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Button } from 'antd-mobile';
import React, { useState } from 'react';
import styles from './index.less';
export default () => {
const [count, setCount] = useState(0);
return (
<div className={styles['adm-button']}>
Hello Alita
<Button
type="button"
color="primary"
fill="solid"
block
size="large"
onClick={() => setCount(count + 1)}
>
点我计数加1 {count}
</Button>
</div>
);
};
5 changes: 5 additions & 0 deletions examples/extends-app/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { request } from '@@/plugin-request';

export async function query(): Promise<any> {
return request('/hello');
}
31 changes: 31 additions & 0 deletions examples/extends-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "dist",
"sourceMap": true,
"jsx": "react",
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2017",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"allowSyntheticDefaultImports": true,
"rootDirs": ["/src", "/root", "/test", "/mock", "./typings"],
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"strict": true,
"paths": {
"@/*": ["./src/*"],
"@@/*": ["./src/.umi/*"],
"alita": ["./src/.umi/*"]
}
}
}
13 changes: 13 additions & 0 deletions examples/extends-app/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.svg';
declare module '*.png';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.gif';
declare module '*.bmp';
declare module '*.tiff';
declare module '*.json';

41 changes: 40 additions & 1 deletion packages/alita/src/features/compatibleMako.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IApi } from 'umi';
import { dirname } from 'path';
import { dirname, join, resolve } from 'path';
import { fsExtra, glob } from '@umijs/utils';
import { copyFileSync, statSync } from 'fs';

export default (api: IApi) => {
// 强制关闭
Expand All @@ -17,6 +19,43 @@ export default (api: IApi) => {
);
}
}
if (api.userConfig.copy) {
const copy = [
{
from: join(
dirname(require.resolve('pdfjs-dist/package.json')),
'cmaps',
),
to: 'build/static/cmaps/',
},
];
const copyDirectory = (opts: any) => {
const files = glob.sync('**/*', {
cwd: opts.path,
dot: true,
});
files.forEach((file: any) => {
const absFile = join(opts.path, file);
if (statSync(absFile).isDirectory()) return;
const absTarget = join(opts.target, file);
fsExtra.mkdirpSync(dirname(absTarget));
copyFileSync(absFile, absTarget);
});
};

copy.forEach((file) => {
const sourcePath = resolve(file.from);
const destinationPath = resolve(
api.userConfig.outputPath || api.paths.absOutputPath,
file.to,
);
copyDirectory({
path: sourcePath,
target: destinationPath,
});
});
}
memo.copy = [];
return memo;
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-extends-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @alita/plugin-exclude-pages

See our website [alitajs](https://alitajs.com) for more information.
Loading

0 comments on commit 078aba6

Please sign in to comment.