@@ -328,6 +328,7 @@ yarn vue-cli-service help # [命令] : 比如 yarn vue-cli-service help test:e2e
328328- 尽量** 不要使用全局注册** (插件/ 组件/ 指令/ 混入等)以优化性能并且代码更清晰、更易维护
329329- 尽量** 按照依赖库的文档描述** 来使用她, 从其源码(src )引入模块(css / scss / ... / js / mjs / ts / jsx / tsx / vue ), 将可能** 不会被处理** 且更可能随版本更新改变, 需要时可以从其构建后的 lib / dist 等目录引入或者增加一些配置(需要了解模块解析及转码规则和相关插件, 不推荐)
330330- 若开发环境出现缓存相关错误信息导致热更新慢, 可以删除 ` node_modules/.cache ` 文件夹再试
331+ - 路由路径不应出现符号 ` . ` , 以方便 ` history 路由 ` 模式开发/ 部署
331332
332333### 风格建议
333334
@@ -656,8 +657,8 @@ yarn vue-cli-service help # [命令] : 比如 yarn vue-cli-service help test:e2e
656657 ` ` `
657658
658659- 所有视图组件可接收props: ` route ` 代替 ` this .$route ` , 区别是: **只在首次进入当前视图或当前视图url发生变化时改变**
659- - 路由视图不需要被缓存的, 可以在meta申明 / ` deactivated ` 钩子销毁实例( ` this .$destroy ()` )或 ` activated ` 钩子进行更新
660- - 为避免渲染错误, 请务必为<b style="color: red;">循环创建的组件</b>**加上 ` key ` **, 特别是 ` tsx / ts / jsx / js ` 中
660+ - **路由视图**不需要被缓存的, 可以在 ` meta ` 申明 /` deactivated ` 钩子销毁实例( ` this .$destroy ()` )或 ` activated ` 钩子进行更新
661+ - 为避免渲染错误, 请务必为 <b style="color: red;">循环创建的组件</b> **加上 ` key ` **, 需要特别注意 ` tsx / ts / jsx / js ` 文件(没有代码提示)
661662
662663### 配置和优化
663664
@@ -699,19 +700,21 @@ yarn vue-cli-service help # [命令] : 比如 yarn vue-cli-service help test:e2e
699700- 开启 ` gzip ` 压缩, 并重用已有 ` gz ` 文件 ` gzip_static on ;`
700701- 缓存静态资源(html 可减少缓存时间)
701702- [HTTP2 Server Push](https://www.nginx.com/blog/nginx-1-13-9-http2-server-push) 服务器推送, 需要 ` nginx ` 版本**1.13.9**及以上, [文档链接](http://nginx.org/en/docs/http/ngx_http_v2_module.html#http2_push_preload)
702- - 多个SPA history路由部署, 只能一个SPA一个location了么(待运维大佬解决)?
703+ - 多个SPA(即 ` html ` 文件)以**history路由**(访问url不以 ` #` 号标识)部署:
704+ - 一个 ` html ` 一个 location 或 待运维大佬完善(示例如下)
705+ - 按照注释修改**每个** ` html ` 的配置, 其中 ` base ` 改为对应访问路径
703706
704707配置示例( ` nginx .conf ` 文件, ` xxx ` 换成对应值):
705708
706709` ` ` bash
707710http {
708- include /etc/nginx /mime.types;
711+ include xxx /mime.types;
709712 default_type application/octet-stream;
710713
711714 # log_format main ' $remote_addr - $remote_user [$time_local] "$request" '
712715 # ' $status $body_bytes_sent "$http_referer" '
713716 # ' "$http_user_agent" "$http_x_forwarded_for"' ;
714- # access_log /var/log/nginx /access.log main;
717+ # access_log xxx /access.log main;
715718
716719 sendfile on;
717720 # tcp_nopush on;
@@ -771,7 +774,7 @@ http {
771774 # error_page 404 /404.html; # 未知页
772775
773776 location / {
774- # rewrite ^/(?:path | path - alias )/ (.* )$ / $1 last ; # 兼容某些路由
777+ # rewrite ^/(?:path | path - alias )/ (.* )$ / $1 last ; # 兼容某些 url
775778 # 设置静态资源缓存(文件名已带内容哈希了)
776779 if ($uri ~ .* \.(?: js | css | jpg | jpeg | gif | png | ico | gz | svg | svgz | ttf | eot | mp4 )$ ) {
777780 expires 7d; # d: 天
@@ -787,7 +790,7 @@ http {
787790
788791 set $u / ; # for 多页history 路由 其他location : ^ / location ([^ / ]+ )
789792 if ($uri ~ ^ / ([^ / ]+ )) {
790- set $u $1.html; # 待测试
793+ set $u $1.html; # 待测试并完善
791794 }
792795 try_files $uri $uri / $uri .html $u / = 404 ;
793796 # try_files $uri $uri / $uri .html / location$u / location = 404 ;
0 commit comments