Skip to content

Commit 79c377c

Browse files
author
caoli
committed
feat:init
0 parents  commit 79c377c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+10956
-0
lines changed

.babelrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
"react",
4+
["env", { "modules": false }]
5+
],
6+
"plugins": [
7+
"react-hot-loader/babel",
8+
"transform-object-assign",
9+
"syntax-dynamic-import",
10+
"transform-object-rest-spread",
11+
["import", { libraryName: "antd", style: "css" }]],
12+
"comments": false
13+
}

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js linguist-language=javascript
2+
*.css linguist-language=javascript
3+
*.html linguist-language=javascript

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.DS_Store
2+
.happypack/
3+
node_modules/
4+
npm-debug.log
5+
.idea/
6+
dist
7+
static
8+
public/
9+
private
10+
run
11+
*.iml
12+
artifacts.json
13+
tmp/
14+
*tmp
15+
_site
16+
logs
17+
app/**/*.js
18+
config/**/*.js
19+
index.js
20+
config/buildConfig.json
21+
config/manifest.json
22+
app/view/*
23+
!app/view/layout.html
24+
!app/view/README.md
25+
!app/view/.gitkeep
26+
package-lock.json

.vscode/settings.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"files.exclude": {
3+
"USE_GITIGNORE": true,
4+
"**/*.js": {
5+
"when": "$(basename).ts"
6+
}
7+
},
8+
"path-intellisense.mappings": {
9+
"lib": "${workspaceRoot}/app/web/lib",
10+
"asset": "${workspaceRoot}/app/web/asset",
11+
"component": "${workspaceRoot}/app/web/component",
12+
"page": "${workspaceRoot}/app/web/page",
13+
"store": "${workspaceRoot}/app/web/store",
14+
},
15+
"typescript.tsdk": "node_modules/typescript/lib"
16+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 sky.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# egg-react-typescript-boilerplate
2+
3+
基于 Egg + React + TypeScript + Webpack3 多页面和单页面服务端客户端渲染同构工程骨架项目.
4+
5+
## 1. 版本
6+
7+
- Egg 版本: ^2.x.x
8+
- Node 版本: Node ^8.x.x+,
9+
- Webpack 版本: ^3.10.1
10+
- React 版本: ^16.0.0
11+
- TypeScript: ^2.6.2
12+
13+
## 2. 文档
14+
15+
- http://hubcarl.github.io/easywebpack/react
16+
- https://zhuanlan.zhihu.com/easywebpack
17+
18+
19+
## 3. 特性
20+
21+
- 支持 Egg Node 端代码 和 前端代码 TypeScript 编写和构建
22+
23+
- 支持 async 和 await 特性, Controller 采用 class 方式编写
24+
25+
- 支持 server 和 client 端代码修改, Webpack 时时编译和热更新, `npm run dev` 一键启动应用
26+
27+
- 基于 react + react-router + react-redux 单页面服务器客户端同构实现
28+
29+
- 支持开发环境, 测试环境,正式环境 Webpack 编译
30+
31+
- 支持 js/css/image 资源依赖, 内置支持CDN特性
32+
33+
- 支持 Webpack DLL 自动化构建
34+
35+
36+
37+
## 4. 依赖
38+
39+
- [easywebpack-react](https://github.com/hubcarl/easywebpack)
40+
- [egg-view-react-ssr](https://github.com/hubcarl/egg-view-react-ssr)
41+
- [egg-webpack](https://github.com/hubcarl/egg-webpack)
42+
- [egg-webpack-react](https://github.com/hubcarl/egg-webpack-react)
43+
44+
## 5. 使用
45+
46+
#### 5.1 安装依赖
47+
48+
```bash
49+
npm install
50+
npm start
51+
```
52+
53+
#### 5.2 启动应用
54+
55+
首次运行请先运行一次 `npm run tsc`
56+
57+
```bash
58+
npm run dev
59+
```
60+
61+
应用访问: http://127.0.0.1:7001
62+
63+
![npm start启动](https://github.com/hubcarl/egg-vue-webpack-boilerplate/blob/master/docs/images/webpack-build.png)
64+
65+
66+
#### 5.3 构建
67+
68+
- TypeScript Egg 构建
69+
70+
```bash
71+
npm run tsc
72+
```
73+
74+
- TypeScript 前端工程构建
75+
76+
```bash
77+
npm run build
78+
```
79+
80+
#### 5.4 打包部署
81+
82+
1. 先运行 `npm run tsc``npm run build` 构建 TypeScript Egg 代码和 TypeScript 前端代码
83+
2. 项目代码和构建代码一起打包代码
84+
3. 应用部署后,通过 `npm start` 启动应用
85+
86+
87+
## License
88+
89+
[MIT](LICENSE)

app/controller/about/about.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Controller } from "egg";
2+
3+
'use strict';
4+
export default class AboutController extends Controller {
5+
async index() {
6+
const { ctx } = this;
7+
await ctx.render('about/about.js', { message: 'react server side render!' });
8+
}
9+
};

app/controller/ant/ant.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
import { Controller } from "egg";
3+
export default class TabController extends Controller {
4+
async tab() {
5+
const { ctx } = this;
6+
await ctx.render('ant/tab/tab.js', {
7+
title:'--ant design server side render--',
8+
keywords:'react, server side render, ant design',
9+
message: { text: 'react ant design server side render demo!'}});
10+
}
11+
};

app/controller/app/app.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Controller } from "egg";
2+
const Model = require('../../mocks/article/list');
3+
export default class AppController extends Controller {
4+
5+
async index() {
6+
const { ctx } = this;
7+
await ctx.render('app/app.js', { url: this.ctx.url.replace(/\/app/, '')});
8+
}
9+
async list() {
10+
const { ctx } = this;
11+
const pageIndex = ctx.query.pageIndex;
12+
const pageSize = ctx.query.pageSize;
13+
ctx.body = Model.getPage(pageIndex, pageSize);
14+
}
15+
16+
async detail() {
17+
const { ctx } = this;
18+
const id = ctx.query.id;
19+
ctx.body = Model.getDetail(id);
20+
}
21+
};

app/controller/css/css.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
import { Controller } from 'egg';
3+
export default class CssModuleController extends Controller {
4+
async cssModule() {
5+
const { ctx } = this;
6+
await ctx.render('css/module/module.js', {
7+
title:'--react server side render--',
8+
keywords:'react, server side render',
9+
message: { text: 'react server side render! support css module test!'}});
10+
}
11+
};

app/controller/hello/hello.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
import { Controller } from 'egg';
3+
export default class HelloController extends Controller {
4+
async element() {
5+
const { ctx } = this;
6+
await ctx.render('hello/element.js', {
7+
title:'--react server side render--',
8+
keywords:'react, server side render',
9+
message: { text: 'react server side render for element!'}});
10+
}
11+
12+
async component() {
13+
const { ctx } = this;
14+
await ctx.render('hello/component.js', {
15+
title:'--react server side render--',
16+
keywords:'react, server side render',
17+
message: { text: 'react server side render for component!'}});
18+
}
19+
};

app/controller/home/home.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Controller } from 'egg';
2+
const Model = require('../../mocks/article/list');
3+
export default class AppController extends Controller {
4+
async index() {
5+
const { ctx } = this;
6+
await ctx.render('home/home.js', Model.getPage(1, 10));
7+
}
8+
9+
async client() {
10+
const { ctx } = this;
11+
await ctx.renderClient('home/home.js', Model.getPage(1, 10));
12+
}
13+
14+
async element() {
15+
const { ctx } = this;
16+
ctx.render('element/element.js', Model.getPage(1, 10));
17+
}
18+
19+
async pager() {
20+
const { ctx } = this;
21+
const pageIndex = ctx.query.pageIndex;
22+
const pageSize = ctx.query.pageSize;
23+
ctx.body = Model.getPage(pageIndex, pageSize);
24+
}
25+
};

app/controller/router/router.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Controller } from "egg";
2+
export default class RouterController extends Controller {
3+
async index() {
4+
const { ctx } = this;
5+
await ctx.render('router/router.js', { message: 'react server side render!' });
6+
}
7+
};

app/controller/spa/spa.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Controller } from 'egg';
2+
export default class SPAController extends Controller {
3+
4+
async client() {
5+
const { ctx } = this;
6+
await ctx.renderClient('spa/client.js', {});
7+
}
8+
9+
async redux() {
10+
const { ctx } = this;
11+
await ctx.renderClient('spa/redux.js', {});
12+
}
13+
14+
async ssr() {
15+
const { ctx } = this;
16+
await ctx.render('spa/ssr.js', { url: ctx.url });
17+
}
18+
};

app/controller/test/test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
export default function (app) {
3+
4+
return class TestController extends app.Controller {
5+
6+
async index() {
7+
const { ctx } = this;
8+
await ctx.render('test/test.js', { title: 'error test', message: 'react server side render!' });
9+
}
10+
11+
};
12+
};

app/index.td.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import AboutController from './controller/about/about';
2+
import AntController from './controller/ant/ant';
3+
import AppController from './controller/app/app';
4+
import CssController from './controller/css/css';
5+
import HelloController from './controller/hello/hello';
6+
import HomeController from './controller/home/home';
7+
import RouterController from './controller/router/router';
8+
import SPAController from './controller/spa/spa';
9+
10+
11+
declare module 'egg' {
12+
export interface Application {
13+
14+
}
15+
16+
export interface IController {
17+
about: {
18+
about: AboutController
19+
},
20+
ant: {
21+
ant: AntController
22+
},
23+
app: {
24+
app: AppController,
25+
},
26+
css: {
27+
css: CssController
28+
},
29+
hello: {
30+
hello: HelloController
31+
},
32+
home: {
33+
home: HomeController
34+
},
35+
router: {
36+
router: RouterController
37+
},
38+
spa: {
39+
spa: SPAController
40+
}
41+
}
42+
43+
export interface IService {
44+
}
45+
46+
function startCluster(options: any)
47+
}

0 commit comments

Comments
 (0)