vue-hackernews-2.0 README

The project's README from github.com/vuejs/vue-hackernews-2.0. As one markdown file: README.md.

vue-hackernews-2.0

HackerNews clone built with Vue 2.0 + vue-router + vuex, with server-side rendering.


Live Demo

Features

Note: in practice, it is unnecessary to code-split for an app of this size (where each async chunk is only a few kilobytes), nor is it optimal to extract an extra CSS file (which is only 1kb) -- they are used simply because this is a demo app showcasing all the supported features.

A Note on Performance

This is a demo primarily aimed at explaining how to build a server-side rendered Vue app, as a companion to our SSR documentation. There are a few things we probably won't do in production if we were optimizing for performance, for example:

It is therefore not recommended to use this app as a reference for Vue SSR performance - instead, do your own benchmarking, and make sure to measure and optimize based on your actual app constraints.

Architecture Overview

screen shot 2016-08-11 at 6 06 57 pm

A detailed Vue SSR guide can be found here.

Build Setup

Requires Node.js 7+

# install dependencies
npm install # or yarn

# serve in dev mode, with hot reload at localhost:8080
npm run dev

# build for production
npm run build

# serve in production mode
npm start

License

MIT

vue-hackernews-2.0 (vuejs/vue-hackernews-2.0)

Searching Database…

这是什么?一个演示应用,使用 Vue 2.0、vue-router 和 Vuex 实现了一个 Hacker News 克隆版,并带有服务端渲染。它是 Vue 官方 SSR 文档的配套项目。
这是框架还是示例应用?它是一个参考/演示应用,不是框架或库。它的用途是供人阅读和学习,展示如何组织一个真实的 SSR Vue 应用。
怎样在本地运行?先用 npm 安装依赖,然后运行 dev 脚本启动 Node 服务器(npm run dev)。如果要用于生产环境,先运行 npm run build 编译客户端和服务端的打包文件,再运行 npm start 提供服务。
运行前需要先安装什么?Node.js 7 或更高版本,以及 npm 4 或更高版本。服务器使用 Express,数据来自 Firebase 提供的 Hacker News API,SSR 则用到 vue、vue-router 和 vue-server-renderer。
可以直接照搬到生产环境的 SSR 方案中吗?不可以。作者提醒不要把它当作性能参考,因为代码分割和 CSS 提取等功能只是为了展示特性而加入的,以这个应用的小规模来看,并不是最优做法。
Hacker News 的数据从哪里来?它使用基于 Firebase 的 HN API。作者指出,这样可以实现实时更新,但会增加打包体积,而且没有高效的批量获取方式。
它是渐进式 Web 应用(PWA)吗?是的,它包含应用清单(manifest)和 Service Worker,演示版还声称 Lighthouse 评分为 100/100。
路由或列表更新方面有什么特别的做法吗?它有路由级别的代码分割、preload/prefetch 资源提示,以及在切换视图时使用 FLIP 动画来实现实时列表更新。
服务端和客户端之间如何管理状态?状态由 Vuex 管理,服务端会预先获取数据,然后客户端根据服务端渲染的结果对 DOM 和状态进行水合(hydrate)。
Creator
vuejs
Size
1 MB
Stars
10.8K
Updated
CommitJan 20
Age
10y
Commits · 90 Days