npm install -g create-react-app
npx create-react-app my-app
1.npm run eject
2.html计算
<script> !(function (win, doc) { function setFontSize() { var baseFontSize = 100; var baseWidth = 320; var clientWidth = document.documentElement.clientWidth || window.innerWidth; var innerWidth = Math.max(Math.min(clientWidth, 480), 320); var rem = 100; if (innerWidth > 362 && innerWidth <= 375) { rem = Math.floor(innerWidth / baseWidth * baseFontSize * 0.9); } if (innerWidth > 375) { rem = Math.floor(innerWidth / baseWidth * baseFontSize * 0.84); } window.__baseREM = rem; document.querySelector('html').style.fontSize = rem + 'px'; } var evt = 'onorientationchange' in win ? 'orientationchange' : 'resize'; var timer = null; win.addEventListener(evt, function () { clearTimeout(timer); timer = setTimeout(setFontSize, 300); }, false); win.addEventListener("pageshow", function (e) { if (e.persisted) { clearTimeout(timer); timer = setTimeout(setFontSize, 300); } }, false); setFontSize(); }(window, document)); </script>
3.webpack-config,js
npm install lib-flexible postcss-px2rem-exclude sass-loader node-sass
const px2rem = require('postcss-px2rem-exclude'); px2rem({ remunit: 75, exclude: /node_modules/i })
4. 入口文件:index.js
import "lib-flexible"
npm start
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。