@@ -40,21 +40,6 @@ https://www.yuque.com/easy-team/egg-vue
40
40
41
41
以上项目,你可以通过 [ easywebpack-cli] ( https://github.com/easy-team/easywebpack-cli ) 初始化。
42
42
43
- ## 版本
44
-
45
- - Egg 版本: ^2.x.x
46
- - Node 版本: ^8.x.x+
47
- - Vue 版本: ^2.5.0
48
- - Webpack 版本: ^4.x.x, 对应 ` easywebpack-vue ` 版本为 ^4.x.x
49
- - Webpack3 版本项目骨架请见 ` webpack3 ` 分支, 对应 ` easywebpack-react ` 版本为 3.x.x
50
-
51
- ## 文档
52
-
53
- - https://easyjs.cn/egg-vue
54
- - https://easyjs.cn/easywebpack
55
- - https://www.yuque.com/easy-team/egg-vue
56
- - https://zhuanlan.zhihu.com/easywebpack
57
-
58
43
## 特性
59
44
60
45
- 支持服务端渲染SSR(Server Side Render), 前端渲染CSR(Client Side Render) 方式
@@ -77,330 +62,36 @@ https://www.yuque.com/easy-team/egg-vue
77
62
78
63
- 提供 国际化 i18n 多语言支持方案
79
64
80
- ## 插件
81
-
82
- - [ easywebpack] ( https://github.com/easy-team/easywebpack ) ^4.x.x
83
- - [ easywebpack-vue] ( https://github.com/easy-team/easywebpack ) ^4.x.x
84
- - [ egg-view-vue-ssr] ( https://github.com/easy-team/egg-view-vue-ssr ) ^3.x.x
85
- - [ egg-webpack] ( https://github.com/easy-team/egg-webpack ) ^4.x.x
86
- - [ egg-webpack-vue] ( https://github.com/easy-team/egg-webpack-vue ) ^2.x.x
87
-
88
- ## 使用
89
-
90
- #### 安装cli(非必需)
91
-
92
- ``` bash
93
- npm install @easy-team/easywebpack-cli -g
94
- ```
95
-
96
- ` easywebpack-cli ` 已内置 ` devDependencies ` 中, 无需安装。如果你需要在命令行使用 ` easy ` 命令, 可以单独全局安装。
65
+ ## 文档
97
66
98
- #### 安装依赖
67
+ - https://easyjs.cn/egg-vue
68
+ - https://easyjs.cn/easywebpack
69
+ - https://www.yuque.com/easy-team/egg-vue
70
+ - https://zhuanlan.zhihu.com/easywebpack
99
71
100
- ``` bash
101
- npm install
102
- ```
72
+ ## 插件
103
73
104
- #### 本地开发
74
+ - [ easywebpack] ( https://github.com/easy-team/easywebpack ) ^5.0.0
75
+ - [ easywebpack-vue] ( https://github.com/easy-team/easywebpack ) ^5.0.0
76
+ - [ egg-webpack] ( https://github.com/easy-team/egg-webpack ) ^5.0.0
77
+ - [ egg-view-vue-ssr] ( https://github.com/easy-team/egg-view-vue-ssr ) ^3.0.0
78
+ - [ egg-webpack-vue] ( https://github.com/easy-team/egg-webpack-vue ) ^3.0.0
105
79
106
- > 启动构建细节请阅读: https://www.yuque.com/easy-team/egg-vue/build
80
+ ## 运行
107
81
108
82
``` bash
83
+ npm run boot
109
84
npm run dev
110
85
```
111
86
112
- 应用访问: http://127.0.0.1:7001
113
-
114
- ![ npm start启动] ( https://github.com/hubcarl/egg-vue-webpack-boilerplate/blob/master/docs/images/webpack-build.png )
115
-
116
- - 本地开发启动 Webpack 构建, 默认配置文件为项目根目录 ` webpack.config.js ` 文件。 SSR 需要配置两份 Webpack 配置,所以构建会同时启动两个 Webpack 构建服务。web 表示构建 JSBundle 给前端用,构建后文件目录 ` public ` , 默认端口 9000; node 表示构建 JSBundle 给前端用,构建后文件目录 ` app/view ` , 默认端口 9001.
117
-
118
- - 本地构建是 Webpack 内存构建,文件不落地磁盘,所以 ` app/view ` 和 ` public ` 在本地开发时,是看不到文件的。 只有发布模式(npm run build)才能在这两个目录中看到构建后的内容。
119
-
120
- #### 线上部署
121
-
122
- > 部署细节请阅读:https://www.yuque.com/easy-team/egg-vue/online
123
-
124
- - 首先在本地或者 ci 进行项目构建
125
-
126
- ``` bash
127
- npm run build
128
- ```
129
-
130
- - 上传源代码以及构建的相关文件到服务器,然后启动应用
87
+ 或
131
88
132
89
``` bash
133
- npm start
134
- ```
135
-
136
- #### 构建配置
137
-
138
- webpack 配置构建是通过 easywebpack 实现的,具体见 https://www.yuque.com/easy-team/egg-vue/qpeiow 和 https://github.com/easy-team/easywebpack-cli
139
-
140
- - Egg Webpack 配置代码调用入口
141
-
142
- ``` js
143
- // ${root}/config/config.local.js
144
- exports .webpack = { // 默认是如下配置,可不配置
145
- // browser: 'http://localhost:7001', // 配置 false 可以关闭自动打开浏览器
146
- // webpackConfigList: require('@easy-team/easywebpack-vue').getWebpackConfig()
147
- };
148
- ```
149
-
150
- - 运行 ` npm run build ` 可以进行 Webpack 项目构建
151
- - 通过 ` easy print ` 可以打印 Webpack 原生配置
152
-
153
- ## 项目结构
154
-
155
- ├── app
156
- │ ├── controller
157
- │ │ ├── test
158
- │ │ │ └── test.js
159
- │ ├── extend
160
- │ ├── lib
161
- │ ├── middleware
162
- │ ├── mocks
163
- │ ├── proxy
164
- │ ├── router.js
165
- │ ├── view
166
- │ │ ├── home
167
- │ │ │ └── home.js // Webpack 服务器编译的jsbundle文件, 对应 app/web/page/home/home.vue
168
- │ └── web // 前端工程目录
169
- │ ├── asset // 存放公共js,css资源
170
- │ ├── framework // 前端公共库和第三方库
171
- │ │ ├── fastclick
172
- │ │ │ └── fastclick.js
173
- │ │ ├── sdk
174
- │ │ │ ├── sdk.js
175
- │ │ ├── storage
176
- │ │ │ └── storage.js
177
- │ │ └── vue // 与vue相关的公开代码
178
- │ │ ├── app.js // 前后端调用入口, 默认引入componet/directive/filter
179
- │ │ ├── component.js // 组件入口, 可以增加component目录,类似下面的directive
180
- │ │ ├── directive // directive 目录,存放各种directive组件
181
- │ │ ├── directive.js // directive引用入口
182
- │ │ └── filter.js // filter引用入口
183
- │ ├── page // 前端页面和webpack构建目录, 也就是webpack打包配置entryDir
184
- │ │ ├── home // 每个页面遵循目录名, js文件名, scss文件名, vue文件名相同
185
- │ │ │ ├── home.scss
186
- │ │ │ ├── home.vue
187
- │ │ │ ├── images // 页面自有图片,公共图片和css放到asset下面
188
- │ │ │ │ └── icon_more.png
189
- │ │ │ └── w-week // 页面自有组件,公共组件放到widget下面
190
- │ │ │ ├── w-week.scss
191
- │ │ │ └── w-week.vue
192
- │ │ └── test // 每个页面遵循目录名, js文件名, scss文件名, vue文件名相同
193
- │ │ └── test.vue
194
- │ ├── store // 引入vuex 的基本规范, 可以分模块
195
- │ │ ├── app
196
- │ │ │ ├── actions.js
197
- │ │ │ ├── getters.js
198
- │ │ │ ├── index.js
199
- │ │ │ ├── mutation-type.js
200
- │ │ │ └── mutations.js
201
- │ │ └── store.js
202
- │ └── component // 公共业务组件, 比如loading, toast等, 遵循目录名, js文件名, scss文件名, vue文件名相同
203
- │ ├── loading
204
- │ │ ├── loading.scss
205
- │ │ └── loading.vue
206
- │ ├── test
207
- │ │ ├── test.vue
208
- │ │ └── test.scss
209
- │ └── toast
210
- │ ├── toast.scss
211
- │ └── toast.vue
212
- ├── build // webpack 自定义配置入口, 会与默认配置进行合并(看似这么多,其实这里只是占个位说明一下)
213
- │ ├── base
214
- │ │ └── index.js // 公共配置
215
- │ ├── client // 客户端webpack编译配置
216
- │ │ ├── dev.js
217
- │ │ ├── prod.js
218
- │ │ └── index.js
219
- │ ├── server // 服务端webpack编译配置
220
- │ │ ├── dev.js
221
- │ │ ├── prod.js
222
- │ │ └── index.js
223
- │ └── index.js
224
- ├── config
225
- │ ├── manifest.json // webpack 构建的资源依赖依赖表
226
- │ ├── config.default.js
227
- │ ├── config.local.js
228
- │ ├── config.prod.js
229
- │ ├── config.test.js
230
- │ └── plugin.js
231
- ├── doc
232
- ├── index.js
233
- ├── public // webpack 编译的前端静态资源存入目录
234
- │ ├── static
235
- │ │ ├── css
236
- │ │ │ ├── home
237
- │ │ │ │ ├── home.07012d33.css
238
- │ │ │ └── test
239
- │ │ │ ├── test.4bbb32ce.css
240
- │ │ ├── img
241
- │ │ │ ├── change_top.4735c57.png
242
- │ │ │ └── intro.0e66266.png
243
- │ ├── test
244
- │ │ └── test.js
245
- │ └── vendor.js // 生成的公共打包库
246
-
247
- ## 功能实现
248
-
249
- ### 多页面服务端渲染/前端渲染同构实现
250
-
251
- #### 多页面前端页面实现
252
-
253
- 在app/web/page 目录下面创建home目录, home.vue 文件, Webpack自动根据.vue文件创建entry入口, 具体实现请见[ webpack.config.js] ( webpack.config.js )
254
-
255
- - home.vue 编写界面逻辑, 根元素为layout(自定义组件, 全局注册, 统一的html, meta, header, body)
256
-
257
- ``` html
258
- <template >
259
- <layout title =" 基于egg-vue-webpack-dev和egg-view-vue插件的工程示例项目" description =" vue server side render" keywords =" egg, vue, webpack, server side render" >
260
- {{message}}
261
- </layout >
262
- </template >
263
- <style >
264
- @import " home.css" ;
265
- </style >
266
- <script type =" text/babel" >
267
-
268
- export default {
269
- components: {
270
-
271
- },
272
- computed: {
273
-
274
- },
275
- methods: {
276
-
277
- },
278
- mounted () {
279
-
280
- }
281
- }
282
- </script >
283
- ```
284
-
285
- #### 多页面后端渲染实现, 通过 ` egg-view-vue-ssr ` 插件 ` render ` 方法实现
286
-
287
- - 创建controller文件home.js
288
-
289
- ``` javascript
290
- exports .index = function * (ctx ) {
291
- // index/index.js 是 app/web/page/index/index.vue 构建后的服务端页面渲染的 JSBundle 文件。
292
- yield ctx .render (' index/index.js' , { message: ' vue server side render!' });
293
- };
294
- ```
295
-
296
- - 添加路由配置
297
-
298
- ``` javascript
299
- app .get (' /home' , app .controller .home .home .index );
300
- ```
301
-
302
- #### 多页面走前端渲染(后端路由)实现, 通过 ` egg-view-vue-ssr ` 插件 ` renderClient ` 方法实现
303
-
304
- - 创建controller文件home.js
305
-
306
- ``` javascript
307
- exports .client = function * (ctx ) {
308
- yield ctx .renderClient (' index/index.js' , { message: ' vue client side render!' });
309
- };
310
- ```
311
-
312
- - 添加路由配置
313
-
314
- ``` javascript
315
- app .get (' /client' , app .controller .home .home .client );
316
- ```
317
-
318
- #### HTML静态页面前端渲染
319
-
320
- - 直接有easywebpack构建出静态HTML文件, 请见 ` webpack.config.js ` 配置和 ` app/web/page/html ` 代码实现
321
-
322
- - 通过 ` egg-static ` 静态文件访问HTML文件
323
-
324
- ### 单页面服务器渲染同构实现
325
-
326
- #### 单页面前端实现
327
-
328
- 在app/web/page 目录下面创建app目录, app.vue, app.js 文件.
329
-
330
- - app.vue 编写界面逻辑, 根元素为layout(自定义组件, 全局注册, 统一的html, meta, header, body)
331
-
332
- ``` html
333
- <template >
334
- <app-layout >
335
- <transition name =" fade" mode =" out-in" >
336
- <router-view ></router-view >
337
- </transition >
338
- </app-layout >
339
- </template >
340
- <style lang =" sass" >
341
-
342
- </style >
343
- <script type =" text/babel" >
344
- export default {
345
- computed: {
346
-
347
- },
348
- mounted (){
349
-
350
- }
351
- }
352
- </script >
353
- ```
354
-
355
- - app.js 页面调用入口
356
-
357
- ``` javascript
358
- import { sync } from ' vuex-router-sync' ;
359
- import store from ' store/app' ;
360
- import router from ' component/app/router' ;
361
- import app from ' ./app.vue' ;
362
- import App from ' app' ;
363
- import Layout from ' component/layout/app' ;
364
-
365
- App .component (Layout .name , Layout);
366
-
367
- sync (store, router);
368
-
369
- export default App .init ({
370
- base: ' /app' ,
371
- ... app,
372
- router,
373
- store
374
- });
375
-
376
- ```
377
-
378
- #### 单页面后端实现
379
-
380
- - 创建controller文件app.js
381
-
382
- ``` javascript
383
- exports .index = function * (ctx ) {
384
- // app/app.js 是 app/web/page/app/app.js 构建后的服务端页面渲染的 JSBundle 文件。
385
- yield ctx .render (' app/app.js' , { url: this .url .replace (/ \/ app/ , ' ' ) });
386
- };
387
- ```
388
-
389
- - 添加路由配置
390
-
391
- ``` javascript
392
- app .get (' /app(/.+)?' , app .controller .app .app .index );
90
+ cd packages/egg-react-webpack-boilerplate
91
+ npm install
92
+ npm run dev
393
93
```
394
94
395
- ## 文章
396
-
397
- > [ https://www.yuque.com/easy-team/egg-vue ] ( https://www.yuque.com/easy-team/egg-vue )
398
-
399
- - 渲染模式细节请阅读:https://www.yuque.com/easy-team/egg-vue/node
400
- - 启动构建细节请阅读:https://www.yuque.com/easy-team/egg-vue/build
401
- - 线上部署细节请阅读:https://www.yuque.com/easy-team/egg-vue/online
402
- - Webpack 入口配置:https://www.yuque.com/easy-team/egg-vue/qpeiow
403
-
404
95
## 交流
405
96
406
97
> 功能性需求或者Bug问题, 欢迎大家 PR 完善, 如果你需要了解更多信息,请加 QQ 群: 433207205 (备注:easyjs)
0 commit comments