github地址

配置文档

环境变量

λ 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的更多相关文章

  1. react create app ,nginx服务器配置

    server{ listen 80; server_name www.domain.com domain.com; location ~* \.js$ { root /home/hard/Projec ...

  2. 利用 Create React Native App 快速创建 React Native 应用

    本文介绍的 Create-React-Native-App 是非常 Awesome 的工具,而其背后的 Expo 整个平台也让笔者感觉非常的不错.笔者目前公司是采用 APICloud 进行移动应用开发 ...

  3. React Native APP结构探索

    APP结构探索 我在Github上找到了一个有登陆界面,能从网上获取新闻信息的开源APP,想来研究一下APP的结构. 附上原网址:我的第一个React Native App 具体来讲,就是研究一个复杂 ...

  4. React Native App设置&Android版发布

    React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...

  5. React Native & app demos

    React Native & app demos https://github.com/ReactNativeNews/React-Native-Apps https://github.com ...

  6. 10 个打造 React.js App 的最佳 UI 框架

    10 个打造 React.js App 的最佳 UI 框架 在本文中,我们将分享一些助你打造 React.js App 最佳的 UI 框架.它们具备你所需要的基本 React 组件,以及易用的 API ...

  7. 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 ...

  8. React & Desktop App

    React & Desktop App https://proton-native.js.org/#/ https://github.com/kusti8/proton-native

  9. [译] Facebook:我们是如何构建第一个跨平台的 React Native APP

    英文原文(需FQ):https://code.facebook.com/posts/1189117404435352/ 早些时候,我们介绍过iOS版的React Native. React Nativ ...

  10. [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 ...

随机推荐

  1. 本机ip、127.0.0.1和0.0.0.0区别及内环流量

    本机ip.127.0.0.1和0.0.0.0区别及内环流量 所谓内环流量 简单的说是指 计算机内部,程序间通讯产生的流量,或者叫 本地流量,对应的是来自网络的流量. 比如,你安装了卡巴斯基,avast ...

  2. dubbo常见错误

    1.dubbo zookeeper注册中心provider的ip地址为内网ip,导致consumer连不上 我用的阿里云的服务器,host默认配置了内网ip,注销或删除即可 vim /etc/host ...

  3. Spring Core Programming(Spring核心编程) - AOP Concepts(AOP基本概念)

    1. What is aspect-oriented programming?(什么是面向切面编程?) Aspects help to modularize cross-cutting concern ...

  4. MySQL在INSERT IGNORE未新增记录时避免AUTO_INCREMENT自增

    在MySQL5.7中做INSERT IGNORE时发现, 即使INSERT未成功执行, 表的自增主键却自动加1了, 在某些情况下需要避免这种行为. 需要修改的变量是 innodb_autoinc_lo ...

  5. Python内置的urllib模块不支持https协议的解决办法

    Django站点使用django_cas接入SSO(单点登录系统),配置完成后登录,抛出“urlopen error unknown url type: https”异常.寻根朔源发现是python内 ...

  6. 像Excel一样使用python进行数据分析

    Excel是数据分析中最常用的工具,本篇文章通过python与excel的功能对比介绍如何使用python通过函数式编程完成excel中的数据处理及分析工作.在Python中pandas库用于数据处理 ...

  7. Python的数据库mongoDB的入门操作

    Python代码: import pymongo # 获取本地端口,激活mongo客户端 client = pymongo.MongoClient('localhost',27017) # 创建一个数 ...

  8. Sublime Text3 运行 PHP 文件

    在 Zend Studio(12.5)下可以通过 Run(Ctrl + F11)把 PHP 程序的执行结果通过 Debug Output 显示在 IDE 中,这样比开启 Server,再打开浏览器执行 ...

  9. 【Shiro】小读Shiro Filter

    类继承结构图 看不明白此图不要紧,后面慢慢提到此图的类: AbstractFilter,抽象过滤器 它实现Filter.继承ServletContextSupport. 它主要实现了init(Filt ...

  10. HTML5+CSS3 效果网站集合

    1.jquery插件库 HTML5制作3D樱花漫天飞舞  http://www.jq22.com/jquery-info3547 2.17素材网   http://www.17sucai.com/pi ...