react-create-app
λ yarn add classnames lodash @material-ui/core react-router-dom mobx mobx-react rxjs
λ yarn add babel-plugin-react-html-attrs @babel/plugin-proposal-decorators @babel/plugin-proposal-class-properties babel-plugin-import --dev
创建tsx
λ npx create-react-app my-app --template typescript
yarn create react-app my-app
// or
npx create-react-app my-app
yarn run eject // 显示所有配置文件
"babel": {
"presets": [
"react-app"
],
"plugins": [
["@babel/plugin-proposal-decorators", {
// "decoratorsBeforeExport": true
"legacy": true
}],
["@babel/plugin-proposal-class-properties", {
// "decoratorsBeforeExport": true
"loose": true
}],
["import", {
"libraryName": "@material-ui/core",
"libraryDirectory": "",
"camel2DashComponentName": false
}, "@material-ui/core"],
["import", {
"libraryName": "lodash",
"libraryDirectory": "",
"camel2DashComponentName": false
}, "lodash"]
]
},
修改打包路径base url
修改路径的 alias
// config/webpack.config.dev.js 和 config/webpack.config.prod.js 大概92行
alias: {
'@': path.resolve(__dirname, '../src'),
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
'react-native': 'react-native-web',
},
// 使用
import store from '@/store'
package.json -> proxy
"proxy":"http://localhost:5000"
let { data } = await axios.get("/users"); // http://localhost:5000/users
多个 proxy
yarn add http-proxy-middleware
// src/setupProxy.js
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy("/api", { targe: "http://localhost:5000" }) // axios('/api/hello') => http://localhost:5000/api/hello
app.use(proxy("/yii", { targe: "http://localhost:5001" }) // axios('/yii/hello') => http://localhost:5001/yii/hello
};
删除.map文件
// scripts/build.js
process.env.GENERATE_SOURCEMAP = false;
polyfill
开启兼容 ie11
yarn add react-app-polyfill
// src/index.js
import 'react-app-polyfill/ie11';
打包优化 babel-minify
npm install babel-minify-webpack-plugin --save-dev
// webpack.config.prod.js
const MinifyPlugin = require("babel-minify-webpack-plugin");
module.exports = {
plugins: [
new MinifyPlugin({}, { comments: false }),
]
}
打包优化 DllPlugin
// 先修改 webpack.config.prod.js
const config2 = [
{
name: "vendor",
mode: "production",
entry: [
"react",
"react-dom",
"lodash",
"axios",
"classnames",
"@material-ui/core",
"mobx",
"mobx-react",
"react-router-dom",
],
output: {
path: path.resolve(__dirname, "..", "public"),
filename: "vendor.js",
library: "vendor_[hash]",
},
plugins: [
new webpack.DllPlugin({
context: __dirname,
name: "vendor_[hash]",
path: path.resolve(__dirname, "..", "public/manifest.dll.json"),
}),
],
},
{
name: "app",
mode: "production",
dependencies: ["vendor"],
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require("../public/manifest.dll.json"),
}),
]
}
]
module.exports = config2;
// 再修改 scripts/build.js 102行
const publicPath = config[1].output.publicPath;
// 修改 public/index.html
<script src="%PUBLIC_URL%/vendor.js"></script>
打包优化 HappyPack
webpack.config.prod.js
// webpack.config.prod.js
yarn add happypack --dev
const HappyPack = require("happypack");
const os = require("os");
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
plugins: [
new HappyPack({
id: "js",
loaders: [
{
loader: "babel-loader",
},
],
threadPool: happyThreadPool,
}),
]
打包优化 UglifyJsPlugin
yarn add uglifyjs-webpack-plugin --dev
// webpack.config.prod.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
plugins: [
new UglifyJsPlugin({
test: /\.js($|\?)/i,
cache: true,
})
]
使用隧道代替 localhost:3000
需要在 devserver 中配置白名单
// webpackDevServer.config.js
allowedHosts: ["a.domin.com"],
react-create-app的更多相关文章
- react create app ,nginx服务器配置
server{ listen 80; server_name www.domain.com domain.com; location ~* \.js$ { root /home/hard/Projec ...
- 利用 Create React Native App 快速创建 React Native 应用
本文介绍的 Create-React-Native-App 是非常 Awesome 的工具,而其背后的 Expo 整个平台也让笔者感觉非常的不错.笔者目前公司是采用 APICloud 进行移动应用开发 ...
- React Native APP结构探索
APP结构探索 我在Github上找到了一个有登陆界面,能从网上获取新闻信息的开源APP,想来研究一下APP的结构. 附上原网址:我的第一个React Native App 具体来讲,就是研究一个复杂 ...
- React Native App设置&Android版发布
React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...
- React Native & app demos
React Native & app demos https://github.com/ReactNativeNews/React-Native-Apps https://github.com ...
- 10 个打造 React.js App 的最佳 UI 框架
10 个打造 React.js App 的最佳 UI 框架 在本文中,我们将分享一些助你打造 React.js App 最佳的 UI 框架.它们具备你所需要的基本 React 组件,以及易用的 API ...
- how to solve error when start Hyper-V quick create app error
After checked the requirements on Hyper-v by run "systeminfo.exe" in cmd window, then I en ...
- React & Desktop App
React & Desktop App https://proton-native.js.org/#/ https://github.com/kusti8/proton-native
- [译] Facebook:我们是如何构建第一个跨平台的 React Native APP
英文原文(需FQ):https://code.facebook.com/posts/1189117404435352/ 早些时候,我们介绍过iOS版的React Native. React Nativ ...
- [React] Create & Deploy a Universal React App using Zeit Next
In this lesson, we'll use next to create a universal React application with no configuration. We'll ...
随机推荐
- Cenos7 部署asp.net core站点
系统版本 rpm -q centos-release --- centos-release--5.1804.el7.centos.x86_64 安装libicu yum install libunwi ...
- 【移动端 Web】怎么循序渐进地开发一个移动端页面
1. 移动页面开发基础 1.1 像素——什么是像素 像素是 Web 页面布局的基础,那么到底什么才是一个像素呢? 像素:一个像素就是计算机屏幕所能显示一种特定颜色的最小区域.这是像素的概念,实际上,W ...
- ionic生成全尺寸icon和splash
http://www.jianshu.com/p/eda363eb28d3 重新添加platform --no-resources可以禁止重新生成icon和splash ionic cordova p ...
- 类中添加log4j日志
在编写代码的时候需要随时查看工作日志,查看工作日志的好处就是随时能检查出错误.所以我一般就需要在编写代码的前期添加工作日志,以便更好的查看相关错误输出. 以一个springmvc小demo为例子 主 ...
- 【C#】C#线程_混合线程的同步构造
目录结构: contents structure [+] 一个简单的混合锁 FCL中的混合锁 ManualResetEventSlim类和SemaphoreSlim类 Monitor类和同步块 Rea ...
- system generator学习笔记【01】
作者:桂. 时间:2018-05-18 18:26:50 链接:http://www.cnblogs.com/xingshansi/p/9045914.html 前言 学习使用system gene ...
- vue-resource和vue-async-data两个插件的使用
vue-resource和vue-async-data两个插件的使用,看了一下文档http://cn.vuejs.org/guide/plugins.html#u5DF2_u6709_u63D2_u4 ...
- 如何用jQuery获取选中行固定列的数据
[本文出自天外归云的博客园] 问题:把选中行的ID统计出来,组成一个数组传给后台(选中行的特点:class为danger) 办法如下: // 多选后点击下线按钮 $("#offline&qu ...
- static在类中的功能
有时候类需要它的一些成员与类本身直接相关,而不是与类的各个对象保持关联. 例如一个银行账户类可能需要一个数据成员来表示当前的利率.在此例中,我们希望利率与类关联,而非与类的每个对象关联.从实现效率上来 ...
- 浏览器神器--vimium
自从学会了正确的坐姿,坐在电脑一整天腰也不酸了.背也不痛了,精神倍棒吃嘛嘛香 zuomeng.png 但奈何使用鼠标久了,手腕.肩膀依旧疼痛.偶尔逛知乎,看到有人推荐chrome浏览器的vimiu ...