Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
学习到章节
5-2
与5-3
时候出现一些问题:1. 异步加载路由会报错
解决方案是使用
mini-css-extract-plugin
代替extract-text-webpack-plugin
,但是只在webpack.config.client.js
使用,不要在webpack.config.server.js
用,issue 链接:webpack-contrib/mini-css-extract-plugin#902. 服务端渲染得到的 js 文件内容是 html 代码
老师的解释是:
所以我就在
webpack.config.base.js
加上publicPath: '/public/'
,不过还没有用,需要配上 devServer 的完整路径://127.0.0.1:8000/public/
。因为如果是/public/
的话,服务端渲染访问静态资源的路径是//127.0.0.1:3333/xxx
,但是服务端没有这种静态资源,而且根据我们写的中间件,所有路由都匹配到handleSSR
这里了,所以打开这个路径,里面的内容都是handleSSR
返回的 html 代码。这一部分其实在之后的章节 5-4 有提到。还有一些其他小问题和可优化的地方,例如安装一个
nodemon
自动重启服务端渲染服务等等。