{"id":20022266,"url":"https://github.com/lucifier129/react-page-template","last_synced_at":"2026-02-27T08:34:10.542Z","repository":{"id":77718184,"uuid":"87908616","full_name":"Lucifier129/react-page-template","owner":"Lucifier129","description":"react 多页应用的模板，支持服务端渲染","archived":false,"fork":false,"pushed_at":"2017-04-11T08:40:32.000Z","size":16,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-25T09:08:48.445Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lucifier129.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-04-11T08:21:24.000Z","updated_at":"2024-07-08T08:38:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"36d4de67-4b7e-44c4-a0f7-5478c2001f83","html_url":"https://github.com/Lucifier129/react-page-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Lucifier129/react-page-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Freact-page-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Freact-page-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Freact-page-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Freact-page-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lucifier129","download_url":"https://codeload.github.com/Lucifier129/react-page-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Freact-page-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29888178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T07:54:54.515Z","status":"ssl_error","status_checked_at":"2026-02-27T07:54:49.177Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T08:39:46.039Z","updated_at":"2026-02-27T08:34:10.524Z","avatar_url":"https://github.com/Lucifier129.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-page-template\nreact 多页应用的模板，支持服务端渲染\n\n## 用法\n\n### 下载依赖\n\n```shell\nnpm install\n```\n\n### 开发理念\n\n#### server-side\n每个页面在 `routes` 目录下开发 node server 端的业务逻辑，包括服务端渲染。\n\nnode 框架是 express，服务端模板引擎也是 `React`，所以 `react` 组件是可以共享的。\n\nexpress view 的路径就配置在 `routes` 目录，可以用 `res.render('home/view', props)` 渲染页面。这种目录设计参考了 [node-hero](https://blog.risingstack.com/node-hero-tutorial-getting-started-with-node-js/)，可以点击查看教程。\n\n``\n#### client-side\n\n每个页面在 `src` 目录下开发浏览器端的业务逻辑，`css|img|html` 文件也可以放到 src 目录下，打包时用 gulp 压缩并拷贝到 dest 目录.\n\n每个页面自己爱用什么 model/store/fetch 都可以自由选择。\n\n\n### 配置server.config.js\n\n`server.config.js` 是 node.js server 端的一些基本配置\n\n```javascript\nimport path from 'path'\nimport pkg from './package'\n// node server 监听的端口，先从环境变量里取值，再从 package.json 的 config.port 里取，默认为 3000\nconst port = process.env.PORT || pkg.config.port || 3000\n\nconst fat = {\n  port: port,\n  locationOrigin: `//localhost:${port}`,\n  restfulApi: '',\n  serverLocationOrigin: `//localhost:${port}`,\n  serverRestfulApi: ''\n}\n\nconst uat = {\n  port: port,\n  locationOrigin: `//localhost:${port}`,\n  restfulApi: '',\n  serverLocationOrigin: `//localhost:${port}`,\n  serverRestfulApi: ''\n}\n\nconst prod = {\n  port: port,\n  locationOrigin: `//localhost:${port}`,\n  restfulApi: '',\n  serverLocationOrigin: `//localhost:${port}`,\n  serverRestfulApi: ''\n}\n\n// 从 package.json 的 config 字段里取 basename 和 env，对应不同的「发布路径」和「发布环境」\nconst basename = pkg.config.vd\nconst env = pkg.config.env.toLowerCase()\nconst envConfigMap = { fat, uat, prod }\nconst envConfig = envConfigMap[env] || envConfigMap.prod\n\n// 输出配置，这个配置包含要传给 view 的一些默认数据\nconst config = {\n  env: env,\n  title: 'test',\n  description: 'test-description',\n  keywords: 'test',\n  basename: basename,\n  // 静态资源的发布路径，可以根据 env 字段，切换成 CND 或者 node static server\n  publicPath: basename + '/static',\n  // 静态资源的本地路径，env 为 prod 生产环境时，会使用 dest 目录下的压缩文件\n  staticPath: path.join(__dirname, 'dest'),\n  // react 服务端渲染时的首次 state\n  initialState: undefined,\n  // seo html 的字段\n  content: '',\n  appSettings: { ...envConfig },\n  ...envConfig\n}\n\nexport default config\n\n```\n\n\n### 启动开发环境\n\n带 webpack-dev-middleware 的模式，该模式不会真正生成文件，而是放到内存里，编译速度较快\n\n```shell\nnpm start\n```\n\n不带 webpack-dev-middleware 的模式，该模式会使用`server.config.js` 里 staticPath 配置目录下的文件\n\n```shell\nnpm run start:prod\n``` \n\n### 打包源文件\n\n该命令会用 gulp 打包 html css img 等资源，用 webpack 打包 js 资源\n\n```shell\nnpm run build\n```\n\n### 配置 webpack 和 gulp\n\nwebpack 和 gulp 配置在 build 目录下。\n\n每个页面都要在 `webpack.config.entry.js` 里配置入口，其中 `vendor` 为大家的公共依赖，每个 page 都要引入 \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucifier129%2Freact-page-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucifier129%2Freact-page-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucifier129%2Freact-page-template/lists"}