[React] Configure a React & Redux Application For Production Deployment and Deploy to Now
In this lesson, we’ll make a few small changes to our scripts and add some environment variables that will be used at build time to get our application ready to be deployed to a production environment using the now
service. Once properly configured, we’ll use the now
CLI and publish our application to a production server.
React support .env file by default, add a .env file in the root folder:
REACT_APP_BASE_URL=http://localhost:9001/todos
which just holding our api configuration.
Also create a .env.production file:
REACT_APP_BASE_URL=./todos
Because we want json-server and our ui using the same domain & port, so here we can just use relative path.
To use the variable in .env, we can do:
const baseUrl = process.env.REACT_APP_BASE_URL; export const getTodos = async () => {
return await fetch(baseUrl)
.then((response) => response.json());
};
Update package.json:
"start": "json-server --static ./build db.json",
"dev": "react-scripts start",
We change the original "start" to "dev".
Because after "build", there will be a "build" folder, so tell json-server to server the build folder and use db.json file a db.
After everything set up, just run:
now
[React] Configure a React & Redux Application For Production Deployment and Deploy to Now的更多相关文章
- 如何优雅地在React项目中使用Redux
前言 或许你当前的项目还没有到应用Redux的程度,但提前了解一下也没有坏处,本文不会安利大家使用Redux 概念 首先我们会用到哪些框架和工具呢? React UI框架 Redux 状态管理工具,与 ...
- 优雅的在React项目中使用Redux
概念 首先我们会用到哪些框架和工具呢? React UI框架 Redux 状态管理工具,与React没有任何关系,其他UI框架也可以使用Redux react-redux React插件,作用:方便在 ...
- 如何在非 React 项目中使用 Redux
本文作者:胡子大哈 原文链接:https://scriptoj.com/topic/178/如何在非-react-项目中使用-redux 转载请注明出处,保留原文链接和作者信息. 目录 1.前言 2. ...
- 【前端】react学习阶段总结,学习react、react-router与redux的这些事儿
前言 借用阮一峰的一句话:真正学会 React 是一个漫长的过程. 这句话在我接触react深入以后,更有感触了.整个react体系都是全新的,最初做简单的应用,仅仅使用react-tools打包js ...
- 【转】浅谈React、Flux 与 Redux
本文转自<浅谈React.Flux 与 Redux>,转载请注明出处. React React 是一个 View 层的框架,用来渲染视图,它主要做几件事情: 组件化 利用 props 形成 ...
- 前端笔记之React(五)Redux深入浅出
一.Redux整体感知 Redux是JavaScript状态管理容器,提供了可被预测状态的状态管理容器.来自于Flux思想,Facebook基于Flux思想,在2015年推出Redux库. 中文网站: ...
- 【React】360- 完全理解 redux(从零实现一个 redux)
点击上方"前端自习课"关注,学习起来~ 前言 记得开始接触 react 技术栈的时候,最难理解的地方就是 redux.全是新名词:reducer.store.dispatch.mi ...
- react聊天室|react+redux仿微信聊天IM实例|react仿微信界面
一.项目概况 基于react+react-dom+react-router-dom+redux+react-redux+webpack2.0+react-photoswipe+swiper等技术混合开 ...
- react,react-router,redux+react-redux 构建一个React Demo
创建初始化应用 加速我们的npm. npm install -g cnpm --registry=https://registry.npm.taobao.org 利用create-react-app ...
随机推荐
- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qvc66dfs/supervisor/
# 安装supervisor 出错 pip3 install supervisor # 解决 sudo pip3 install supervisor
- Windows上Python2与Python3同时安装、共存
一.选择 Python2 还是 Python3?当然是全都要 Python3 虽是未来,不过 Python2 的用户群体仍然膨大,网上有大量优良的项目和模块可供使用,遇到问题也基本可以找到解决方法,推 ...
- MySQL Field排序法
检索 id = 2 or id = 5 or id = 9 or id = 56 or id = 38.然后按照 2 , 5, 9, 56, 38 这个顺序排列,这是题目要求 以下为解决方案: 1 ...
- 73.node.js开发错误——TypeError: Cannot set property 'XXX' of undefined
转自:https://blog.csdn.net/fd214333890/article/details/53467429
- POJ 1991 DP
题意: 思路: 考虑DP 先把事件按照地点顺序排个序 f[i][j][0]表示从i到j还没有去过 现在在i f[i][j][1]表示从i到j还没有去过 现在在j 那么方程就呼之欲出了 f[i][j][ ...
- Oracle 启动失败报错“TNS-12555: TNS:permission denied”解决办法
[oracle@testdb admin]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-FEB- ...
- xsy3320 string
xsy3320 string 题意: 给一颗树,每条边上有一个字符,求有多少条路径是回文的.(\(N\leq50000\),\(c\in\{1,2\}\)) 题解: 前置芝士:回文前缀& ...
- 软考之路--从生活着手,看PV怎样操作
PV操作.是软考其中一个非常重要的考点,一听到这个名词,顿时赶脚高大上有么有,在软考的历年试题中,也不乏PV操作的身影,老师也对PV操作进行了一次讲课,那时年少.听得稀里糊涂,也不是非常理解,在小编的 ...
- 兔子--ps中的基本工具总结(ps cs5)
矩形选框工具 椭圆选框工具 单行选框工具 单列选框工具 移动工具 套索工具柜 多边形套索工具 磁性套索工具 魔棒工具 高速选择工具 裁剪工具 切片工具 切片选择工具 吸管工具 颜色取样器工具 标尺工具 ...
- Flex 正則表達式 电话、邮箱验证
一.经常使用验证 验证数字:^[0-9]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(0|[1-9 ...