[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 ...
随机推荐
- SpringBoot常用注解的介绍及使用 - 转载
常用注解 @springBootApplication 系统启动类注解,此注解是个组合注解,包括了:@SpringBootConfiguration,@EnableAutoConfiguration, ...
- GridControl添加右键菜单
private void gridView1_MouseDown(object sender, MouseEventArgs e) { GridHitInfo vi = gridView1.CalcH ...
- <LeetCode OJ> 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- msp430在ccsv5下出现的问题总结
一.内存问题 问题描写叙述,报错: program will not fit into available memory. placement with alignment fails for se ...
- Scrum中的产品需求预审
原文作者:Mike Cohn 为了保持产品待办事项(product backlog)的整洁有序,我们须要召开product backlog refinement会议(有时也叫product backl ...
- HTTP请求具体解释
1. HTTP请求格式 做过Socket编程的人都知道,当我们设计一个通信协议时,"消息头/消息体"的切割方式是非经常常使用的.消息头告诉对方这个消息是干什么的,消息体告诉对方怎么 ...
- CRSF Defense Using Content Injection Support By ModSecurity
The most advanced and imaginative use of the content injection feature is that devised byRyan C. Bar ...
- 使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)
你是否遇到过这样的情况:从终端软件登录远程的Linux主机,将一堆很大的文件压缩为一个.tar.gz文件,连续压缩了半个小时还没有完成,这时,突然你断网了,你登录不上远程Linux主机了,那么前面的半 ...
- IOS打包发布APP的所有详细流程
其他一些不错的参考:点击打开链接 一.申请苹果开发者账号 首先需要申请苹果开发者账号才能在APP store 里发布应用. 开发者账号分为:(1)个人开发者账号 (2)企业开发者账号 主要的区 ...
- 在Vue单页面应用中使用Promise链式调用
eg: this.commonLoginFun().then((res) => { if (res.errNo === 0) { const { isLogin } = res.data; if ...