--max_old_space_size
命令强制分配内存来避免node进程 out of memory
项目前端相关指标:html
\ | 业务代码大小 | 打包后代码总量 | 路由数量 | 编译总时长 | 热加载时长 |
---|---|---|---|---|---|
总量 | 5.26 MB | 35.5MB | 近100个 | 20分 | 45 s |
==能够看到前端编译的时间已经极大的影响了开发人员的开发时间和开发效率==前端
功能模块
为第一维度分割大项目。location
分发到不一样静态目录。hash
模式改成history
模式/src/index.js:
node
import browserHistory from 'history/createBrowserHistory'; const app = dva({ history: browserHistory(), });
package.json
/src/index.ejs
首页文件中非本项目的文件引入nginx.conf:
nginx
location /sub-path/ { alias /xxx/dist/; #静态文件路径 try_files $uri $uri/ /xxx/dist/index.html; #404时从新定向到静态文件目录下的index.html下 }
nginx.conf:
json
location / { alias /xxxx/dist/; #静态文件路径 try_files $uri $uri/ /xxxx/dist/index.html; #404时从新定向到静态文件目录下的index.html下 }
nginx
前端404路由
和nginx404路由
同时存在致使无限刷新需缓存一个更新状态在本地,防止死刷新tryRefresh() { if (window.sessionStorage.getItem('refresh') === 'true') { window.sessionStorage.removeItem('refresh'); this.show404 = true; } else { window.sessionStorage.refresh = 'true'; this.show404 = false; window.location.href = window.location.href; } }
setDefaultOpenKeys() { try { const { location: { pathname } } = this.props; let keys = []; const pathItems = pathname.replace('/', '', 1).split('/'); const pathItemsWithoutLast = pathItems.slice(0, pathItems.length-1); this.setState({ openKeys: pathItemsWithoutLast, }); } catch (err) { // what you do } }
将前端代码拆分红为一个基础模板和3个子项目。后端
\ | 业务代码大小 | 打包后代码总量 | 路由数量 | 编译总时长 | 热加载时长 |
---|---|---|---|---|---|
==项目 - 旧== | ==5.26 MB== | ==35.5MB== | ==近100个== | ==20分== | ==45 s== |
项目模板 | 0.45 MB | 2MB | 2个 | 15s | 1 s |
子项目一 | 3.5 MB | 28MB | 近70个 | 12分 | 7 s |
子项目二 | 4.2 MB | 12MB | 10个 | 4分 | 5 s |
子项目三 | 2 MB | 9.16MB | 16个 | 1.5分 | 2 s |