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. Eclipse/myEclipse 代码提示/自动提示/自动完成设置

    设置eclipse/myEclipse代码提示可以方便开发者,不用在记住拉杂的单词,只用打出首字母,就会出现提示菜单.如同dreamweaver一样方便. 1.菜单window->Prefere ...

  2. Coursera机器学习+deeplearning.ai+斯坦福CS231n

    日志 20170410 Coursera机器学习 2017.11.28 update deeplearning 台大的机器学习课程:台湾大学林轩田和李宏毅机器学习课程 Coursera机器学习 Wee ...

  3. Elasticsearch集群运维

    一.索引管理 1. 创建索引 PUT test-2019-03 { "settings": { "index": { "number_of_shard ...

  4. JavaScript单独的模块中传递数据

    首先我们来看看这张图,让我们来思考一下! 下买我给出我的完整思路代码 html代码: <!DOCTYPE html> <html lang="zh-CN"> ...

  5. [转]numpy 100道练习题

    100 numpy exercise 翻译:YingJoy 网址: https://www.yingjoy.cn/ 来源:https://github.com/rougier/numpy-100 Nu ...

  6. C#反射实现 C# 反射 判断类的延伸类型 使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码 C# ADO.NET的SqlDataReader对象,判断是否包含指定字段 页面中添加锚点的几种方式 .net 简单实用Log4net(多个日志配置文件) C# 常用小点

    C#反射实现   一.反射概念: 1.概念: 反射,通俗的讲就是我们在只知道一个对象的内部而不了解内部结构的情况下,通过反射这个技术可以使我们明确这个对象的内部实现. 在.NET中,反射是重要的机制, ...

  7. Navicat Premium 12破解方法

    来源网址:https://www.jianshu.com/p/42a33b0dda9c 1.按步骤安装Navicat Premium,如果没有可以去官网下载:http://www.navicat.co ...

  8. MYSQL 优化器 源码解析

    http://www.unofficialmysqlguide.com/introduction.html https://dev.mysql.com/doc/refman/8.0/en/explai ...

  9. XSS测试代码

    无script的Xss <img/src=# onerror=alert('XSS')> HTML5  XSS测试代码 <video> <source onerror=” ...

  10. mysql索引知识简单记录

    简介 今天记录下索引基础知识  1.mysql单表最多支持多少个索引,索引总长度为多少? 索引是在存储引擎中实现的,因此每种存储引擎的索引都不一定完全相同,并且每种存储引擎也不一定支持所有索引类型. ...