Not every app is greenfield, and it would be a shame if existing React apps could not benefit from the micro-size of Preact. In this lesson we’ll discuss what preact-compat is, how to use it, and some examples of the file-size savings available. https://github.com/developit/preact-compat

Create a new react app:

create-react-app preact-demo

Build:

npm run build

You can see that the size of main bundle file is 43kb.

Now let's run:

npm run eject

Install:

npm install --save preact preact-compat

open config/webpack.config.prod.js:

    alias: {

      // 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',
'react': 'preact-compat',
'react-dom': 'preact-compat'
},

In 'alias' field, add tow fields for preact.

Run the build again. Now you can see that the bundle size is '13KB'!

[PReact] Reduce the Size of a React App in Two Lines with preact-compat的更多相关文章

  1. 使用create react app教程

    This project was bootstrapped with Create React App. Below you will find some information on how to ...

  2. react系列笔记1 用npx npm命令创建react app

    react系列笔记1 用npx npm命令创建react app create-react-app my-app是开始构建新的 React 单页应用程序的最佳方式.它已经为你设置好了开发环境,以便您可 ...

  3. tap news:week5 0.0 create react app

    参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...

  4. Create React App

    Facebook开源了React前端框架(MIT Licence),也同时提供了React脚手架 - create-react-app. create-react-app遵循约定优于配置(Coc)的原 ...

  5. How to reduce Index size on disk?减少ES索引大小的一些小手段

    ES索引文件瘦身总结如下: 原始数据:(1)学习splunk,原始data存big string(2)原始文件还可以再度压缩倒排索引:(1)去掉不必要的倒排索引信息:例如文件位置倒排._source和 ...

  6. [Poi] Customize Babel to Build a React App with Poi

    Developing React with Poi is as easy as adding the babel-preset-react-appto a .babelrc and installin ...

  7. [Parcel] Bundle a React App with Parcel

    Parcel comes in as the new cool kid in the bundlers world. Unlike other bundlers which take lots of ...

  8. Create React App 安装less 报错

    执行npm run eject 暴露模块 安装 npm i  less less-loader -D 1.打开 react app 的 webpack.config.js const sassRege ...

  9. 如何扩展 Create React App 的 Webpack 配置

    如何扩展 Create React App 的 Webpack 配置  原文地址https://zhaozhiming.github.io/blog/2018/01/08/create-react-a ...

随机推荐

  1. Java开发者最经常使用19个Linux命令

    1.查找文件 find / -name filename.txt 依据名称查找/文件夹下的filename.txt文件. 2.查看一个程序是否执行 ps –ef|grep tomcat 查看全部有关t ...

  2. windows下硬盘安装debian

    windows下硬盘安装debian 此方法在 windows8.1 + debian8.7.1 可用 配置系统安装镜像 1 在windows下格式化一个fat32的分区 2 把下载的debian-7 ...

  3. 7.Node.js 创建第一个应用

    转自:http://www.runoob.com/nodejs/nodejs-tutorial.html 如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器, ...

  4. jQuery post 传递 iframe

    //使用POST链接iframe function doOpenPostIfrm(url, args, iframe) { //创建一个隐藏表单 var _form = $("<for ...

  5. select发生改变使用js提交form表单(get传值)

    form表单如下: <form id="my_form" method="get" action=""> <input t ...

  6. sql之group by的用法

    1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简 ...

  7. POJ 2427 Smith's Problem Pell方程

    题目链接 :  http://poj.org/problem?id=2427 PELL方程几个学习的网址: http://mathworld.wolfram.com/PellEquation.html ...

  8. Javascript 6 种继承

    1.原型链继承 // 1.原型链继承的两个问题===>在借用构造函数中可以解决下下面的两个问题//problem: 在创建子类型的实例时,不能向超类型的实例传递参数(在这里就是不能向A()里传递 ...

  9. USACO 2009 Dec cow toll paths 过路费-floyd

    这道题首先要明确一点,那就是当你从一个点走到自己时,也是需要花费这个点点权值的费用.这个点卡了我两次QWQ 然后我比较喜欢分两步搞: 首先,我们利用floyd的一个性质:就是在更新其他点之间的路线时要 ...

  10. Linux的用户和组管理

    1.用户和组 一个用户必须有一个主组 一个用户可以同时属于多个组 一个组可以拥有多个用户 用户信息存在: /etc/passwd 组信息存在:/etc/group 密码信息存在: /etc/shado ...