egg服务器如何加载vue框架工程的生产环境静态资源
前端渲染的话直接构建到 public 目录。后端的话看 egg-view-vue
发自我的 iPhone
在 2017年9月28日,10:29,seric705 notifications@github.com 写道:
egg服务器如何加载vue框架工程的生产环境静态资源
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
可以请求静态资源了,那可不可以在请求资源的时候不加上public么,我vue框架用webpack打包出来的生产环境代码都是绝对路径的,放在/static路径下的

egg-static 的 prefix 自己设置,但不建议。静态资源一般最好放 cdn 去,放 egg 下的话,有个 prefix 好一点,避免和 router 冲突,反正用户又看不到静态资源的地址,入口页你自己写个 router 渲染出来就好了。
我试了下面的方法可以
1.在config.default.js里将prefix设置成'/static'
2.将vue项目生产环境代码中static目录下的css、js、images等文件放到egg服务器public目录下
3.将vue项目生产环境代码中index.html复制为egg服务器view/redirect/index.tpl
这样能够渲染出页面,保留了prefix,虽然有点麻烦



const fs = require('mz/fs');
const tpl = path.join(this.app.config.static.dir, 'index.html');
// 如果没变化的话可以 cache 起来,不用每次 read
this.ctx.body = yield fs.readFile(tpl, 'utf-8');
Most helpful comment