知乎新版的前端技术架构是什么?

知乎新版的前端技术架构是什么?

最初我确实获得了源码,后来考虑到安全性等原因撤掉了原答案。现在知乎已经修复了问题,再次修改回原答案。(已将之前公开的源码删除)。

至于我是如何“偶然获取到源码”的,请参看该文章谈谈我是如何获得知乎的源码的 - 知乎专栏,该文末提供工具。

------------------ 最早的答案 -----------------

偶然获取到了知乎页面内右下角那个提交反馈功能的源码,进行了以下的分析 源码目录如下

依赖库目录如下

我们可以看到其中有以下依赖库:

- [preact](https://github.com/developit/preact) react的优化版本,体积小,快速,同样的ES2015 API

- [babel(babel-runtime)](https://github.com/babel/babel) 帮你用最新的语法写JS - [webpack](https://github.com/webpack/webpack) 打包以及处理依赖关系

- [classnames](http://jedwatson.github.io/classnames) 拼接className的工具

- [css-loader](https://github.com/webpack-contrib/css-loader) css loader module for webpack

- [style-loader](https://github.com/webpack-contrib/style-loader) style loader module for webpack

- [core-js](https://github.com/zloirock/core-js) Polyfill库

- [punycode](https://github.com/bestiejs/punycode.js) (有关DNS,不懂做什么用的)

- [querystring](https://github.com/Gozala/querystring) 解析和拼接querystring

- [css-mediaquery](https://github.com/ericf/css-mediaquery) Parses and determines if a given CSS Media Query matches a set of values via JavaScript.

- [cssom](https://github.com/NV/CSSOM) CSS解析器

- url (貌似是Node的标准模块,找了找没找到,没有继续花时间找)

还有以下一些依赖,同出自一个叫做[Christoph Burgmer](https://github.com/cburgmer)的人之手,恕我眼拙,不知道这是何方高人。不过有意思的是,除了第一个stars较高以外,其他几个都没有很多stars。

- [rasterizehtml](http://www.github.com/cburgmer/rasterizeHTML.js) 873 stars 在Canvas里绘制HTML(好NB的样子)

- [ayepromise](https://github.com/cburgmer/ayepromise) 21 stars 体积极小的Promise库(话说core-js里不是有了吗?)

- [xmlserializer](https://github.com/cburgmer/xmlserializer) 19 stars DOM转XML或XHTML

- [inlineresources](https://github.com/cburgmer/inlineresources) 9 stars 不懂

- [css-font-face-src](https://github.com/cburgmer/css-font-face-src) 1 stars 解析@font-face

- [sane-domparser-error](https://github.com/cburgmer/sane-domparser-error) 0 stars 转换DOMParser和XHR返回的错误

**数据层**

由于功能简单,数据量小,没有用到Flux或Redux之类的数据管理框架(类库)。也因此数据交互直接放到了React Component里。 FormData里只有message, user, extra, image字段。

**数据访问**

数据访问在lib/http.js,是一个仅有35行,没有考虑太多兼容性的版本。

**屏幕截图**

提交反馈时会有一个屏幕截图功能。源码在lib/captureScreen.js中,调用了这个NB库[rasterizehtml](http://www.github.com/cburgmer/rasterizeHTML.js),将HTML画到canvas上。

**本地存储**

在lib/features.js中,有调用`localStorage`。

**ESLint**

发现了eslint-disable-line等。

------------- 以下为后来的临时答案 ---------------

由于我**没有源码**,所以试着搜索关键字找出知乎可能用到的框架或类库:

先用chrome打开页面,并开启devTools,在所有代码中搜索

首页https://www.zhihu.com/

搜索关键词 所属框架或类库

问答页面https://www.zhihu.com/question/56236151/answer/149122097

搜索关键词 所属框架或类库

标签:知乎,架构,新版,Web 开发,前端开发,JavaScript,知乎技术实现