提交 4f93ea1562a08d7f140adc258f6df475530ae67a

作者 sorrycc
1 个父辈 f035d04e

chore: update blocks and improve the local dev expirence

  1 +
1 export default { 2 export default {
2 plugins: [ 3 plugins: [
3 ['umi-plugin-block-dev', { 4 ['umi-plugin-block-dev', {
4 - 'layout': 'ant-design-pro', 5 + layout: process.env.LAYOUT || 'ant-design-pro',
  6 + menu: {
  7 + name: process.env.BLOCK,
  8 + icon: 'home',
  9 + },
5 }], 10 }],
6 ['umi-plugin-react', { 11 ['umi-plugin-react', {
7 'dva': true, 12 'dva': true,
8 'antd': true, 13 'antd': true,
9 - }] 14 + }],
  15 + require.resolve('./plugin'),
10 ], 16 ],
11 -} 17 +};
1 # umi-blocks 1 # umi-blocks
2 2
3 -Official collection of some high quality blocks. 3 +Official block collection from umi community.
4 4
5 ## Usage 5 ## Usage
6 6
7 -```shell  
8 -$ umi block list  
9 -$ umi block add [A block name in list, or any github address of a umi block] 7 +### Install Dependencies
  8 +
  9 +```bash
  10 +$ yarn
10 ``` 11 ```
11 12
12 -You can visit umi [doc](https://umijs.org/guide/block.html) for find out more info about umi block. 13 +### View Block or Template
13 14
14 -## Contribute 15 +> Specify the block via BLOCK env.
15 16
16 -You can create a umi block and make a PR for us! 17 +```bash
  18 +$ BLOCK=templates/user-dashboard yarn start
  19 +```
17 20
18 -How to create a block: 21 +### Create Block
19 22
20 -```shell  
21 -$ yarn create umi --block 23 +```bash
  24 +# Create
  25 +$ BLOCK=templates/my-template yarn run create
  26 +
  27 +# Debug
  28 +$ BLOCK=templates/my-template yarn start
22 ``` 29 ```
  30 +
  31 +You can visit umi [doc](https://umijs.org/guide/block.html) for find out more info about umi block.
  32 +
  33 +If you are done, make a PR for this.
  34 +
  35 +## LICENSE
  36 +
  37 +MIT
1 { 1 {
2 "name": "Blank", 2 "name": "Blank",
3 - "description": "A blank block for quick start a umi page develop.", 3 + "description": "Blank block for quick start a umi page develop, with mock, dva, service and antd.",
4 "dependencies": { 4 "dependencies": {
5 "umi-request": "^1.0.0" 5 "umi-request": "^1.0.0"
6 } 6 }
1 -export default {  
2 - plugins: [  
3 - ['umi-plugin-block-dev', {  
4 - layout: 'ant-design-pro',  
5 - }],  
6 - ['umi-plugin-react', {  
7 - antd: true,  
8 - }],  
9 - ],  
10 -}  
1 { 1 {
2 "name": "Demo", 2 "name": "Demo",
3 - "description": "A demo block of umi.", 3 + "description": "Demo block of umi, with antd.",
4 "dependencies": { 4 "dependencies": {
5 "antd": "^3.10.9" 5 "antd": "^3.10.9"
6 } 6 }
1 { 1 {
2 "private": true, 2 "private": true,
3 "scripts": { 3 "scripts": {
  4 + "start": "UMI_UI=none umi dev",
4 "lint:style": "stylelint \"src/**/*.less\" --syntax less", 5 "lint:style": "stylelint \"src/**/*.less\" --syntax less",
5 "lint": "eslint --ext .js src mock tests && npm run lint:style", 6 "lint": "eslint --ext .js src mock tests && npm run lint:style",
6 "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style", 7 "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style",
@@ -10,6 +11,7 @@ @@ -10,6 +11,7 @@
10 "build": "node ./_scripts/generate.js" 11 "build": "node ./_scripts/generate.js"
11 }, 12 },
12 "devDependencies": { 13 "devDependencies": {
  14 + "@ant-design/pro-layout": "^4.5.16",
13 "babel-eslint": "^10.0.1", 15 "babel-eslint": "^10.0.1",
14 "eslint": "^5.4.0", 16 "eslint": "^5.4.0",
15 "eslint-config-airbnb": "^17.0.0", 17 "eslint-config-airbnb": "^17.0.0",
@@ -30,7 +32,8 @@ @@ -30,7 +32,8 @@
30 "stylelint-config-standard": "^18.0.0", 32 "stylelint-config-standard": "^18.0.0",
31 "umi": "^2.3.0-0", 33 "umi": "^2.3.0-0",
32 "umi-plugin-block-dev": "^2.0.0", 34 "umi-plugin-block-dev": "^2.0.0",
33 - "umi-plugin-react": "^1.3.0-0" 35 + "umi-plugin-react": "^1.3.0-0",
  36 + "umi-request": "^1.2.6"
34 }, 37 },
35 "lint-staged": { 38 "lint-staged": {
36 "x/**/*.{js,ts,tsx,json,jsx,less}": [ 39 "x/**/*.{js,ts,tsx,json,jsx,less}": [
  1 +import { join } from 'path';
  2 +import { readdirSync } from 'fs';
  3 +
  4 +if (process.env.BLOCK) {
  5 + process.env.PAGES_PATH = join(process.env.BLOCK, 'src');
  6 +} else {
  7 + console.log(`
  8 +Please specify the BLOCK env,
  9 +
  10 +e.g.
  11 +
  12 +$ BLOCK=templates/user-dashboard yarn start
  13 +$ BLOCK=blocks/blank yarn start
  14 + `.trim());
  15 + process.exit(1);
  16 +}
  17 +
  18 +function getRoutes(type) {
  19 + const dirs = readdirSync(join(__dirname, type));
  20 + const routes = [];
  21 + for (const dir of dirs) {
  22 + if (dir.charAt(0) === '.') continue;
  23 + routes.push({
  24 + path: `/${type}/${dir}`,
  25 + component: join(type, dir, 'src', 'index.js'),
  26 + });
  27 + }
  28 + return routes;
  29 +}
  30 +
  31 +function getRoute() {
  32 + return {
  33 + path: '/',
  34 + component: join(process.env.BLOCK, 'src', 'index.js'),
  35 + };
  36 +}
  37 +
  38 +export default (api) => {
  39 + api.modifyRoutes(routes => {
  40 + routes[0].routes = [
  41 + getRoute(),
  42 + // ...getRoutes('blocks'),
  43 + // ...getRoutes('templates'),
  44 + ...routes[0].routes.slice(1),
  45 + ];
  46 + return routes;
  47 + });
  48 +};
1 -export default {  
2 - plugins: [  
3 - ['umi-plugin-block-dev', {}],  
4 - ['umi-plugin-react', {  
5 - antd: true,  
6 - dva: true,  
7 - }],  
8 - ],  
9 -}  
1 { 1 {
2 "name": "UserDashboard", 2 "name": "UserDashboard",
3 - "description": "User dashboard example.", 3 + "description": "User dashboard example with umi, antd and dva.",
4 "dependencies": { 4 "dependencies": {
5 "antd": "^3.23.4", 5 "antd": "^3.23.4",
6 "umi-request": "^1.0.0" 6 "umi-request": "^1.0.0"

85.6 KB | 宽: | 高:

85.2 KB | 宽: | 高:

  • 两方对比
  • 交换覆盖
  • 透明覆盖
注册登录 后发表评论