zoukankan      html  css  js  c++  java
  • [PReact] Reduce the Size of a React App in Two Lines with preact-compat

    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'!

  • 相关阅读:
    Kakuro Extension HDU
    CodeForces
    HDU
    2019牛客暑期多校训练营(第二场)F.Partition problem
    UVA
    团队冲刺6
    团队冲刺4
    团队冲刺3
    团队冲刺2
    团队冲刺1
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7042149.html
Copyright © 2011-2022 走看看