Ant-design-pro: npm run build之后怎么访问mock数据呢

Created on 16 Apr 2018  ·  11Comments  ·  Source: ant-design/ant-design-pro

有时候只想要展示个demo, 不想要连真实的数据库(甚至后端都没写好), npm start可以访问mock数据, 但是npm run build之后mock数据是没有打包进去的, 有没有办法把mock数据整合进去呢。

需求跟https://github.com/ant-design/ant-design-pro/issues/992 差不多

https://github.com/sorrycc/roadhog/issues/334 说貌似不支持。

但是我看https://preview.pro.ant.design 就是没有发api请求, 请问是怎么做的呢? 谢谢~

Most helpful comment

@u3u @chenshuai2144 弄好了, 谢谢~ 😅, 昨天理解错了, 以为是roadhog-api-doc static只生成了api.html, api.js, api.css三个文件, 然后把这三个copy出来跟之前用npm run build生成的文件部署在一起😯。 原来是roadhog-api-doc static就生成了所有需要的文件。。 thanks~

All 11 comments

Translation of this issue:


How to access mock data after ## npm run build

Sometimes you just want to show a demo, don't want even a real database (even the back end is not written), npm start can access mock data, but after 'npm run build` the mock data is not packaged in. There is no way to integrate mock data into it.

The requirements are similar to https://github.com/ant-design/ant-design-pro/issues/992

Https://github.com/sorrycc/roadhog/issues/334 It seems that it does not seem to support it.

But I see https://preview.pro.ant.design there is no api request, how does it do? Thank you~

静态站点生成

项目根目录,运行:

$ roadhog-api-doc static

会生成三个文档站点静态文件:api.html、api.js、api.css,你可以将其部署到自己的站点中供线上访问,这里的数据已经被静态化(转换网络请求为代码数据)。

https://pro.ant.design/docs/api-doc-cn

接口静态化?

@u3u 你好, 3x, 我看了https://pro.ant.design/docs/api-doc-cn

$ roadhog-api-doc build

这个最后会生成api.html, api.js, api.css, 我单独部署了之后, 然后要怎么才能跟ant-design-pro build之后的静态文件一起使用呢, 怎么才能部署成像https://preview.pro.ant.design/ 这样, 不需要访问外部的api呢?

@chenshuai2144 你好, 想请问怎么才能部署成像https://preview.pro.ant.design/ 这样, 不需要访问外部的api呢?

@magicly 我不是已经说了么

项目根目录,运行:

$ roadhog-api-doc static

执行之后会静态化 mock 数据,你只需要部署 dist 目录即可

$ serve -s dist

楼上说的对

@u3u @chenshuai2144 弄好了, 谢谢~ 😅, 昨天理解错了, 以为是roadhog-api-doc static只生成了api.html, api.js, api.css三个文件, 然后把这三个copy出来跟之前用npm run build生成的文件部署在一起😯。 原来是roadhog-api-doc static就生成了所有需要的文件。。 thanks~

@u3u 你好,请问这个

roadhog-api-doc static

命令是 ant 团队 定制化的吗? 我想在一个用roadhog创建的app build之后使用mock data..

@magicly 我不是已经说了么

项目根目录,运行:

$ roadhog-api-doc static

执行之后会静态化 mock 数据,你只需要部署 dist 目录即可

$ serve -s dist

找不到roadhogrc.mock.js文件,求助

第一版还有.roadhogrc.mock.js这个文件,v2就没了。 @u3u 麻烦更新一下解决方法。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renyi818 picture renyi818  ·  3Comments

wuyongdec picture wuyongdec  ·  3Comments

suifan picture suifan  ·  3Comments

yjz1004 picture yjz1004  ·  3Comments

Jerry-goodboy picture Jerry-goodboy  ·  3Comments