npm install -g create-react-app
create-react-app demo01
const { override, addWebpackAlias } = require('customize-cra')
const path = require('path')
module.exports = override(
addWebpackAlias({
'@': path.join(__dirname, './src')
})
)
"scripts": {
"start": "set PORT= 7003 && react-app-rewired start",
"build": "react-scripts build",
}
"scripts": {
"start": "set PORT= 6001 && react-scripts start",
"build": "react-app-rewired build",
},
npm i postcss-loader autoprefixer
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 11"
],
3.根目录新建 postcss.config.js 配置如下
module.exports = {
plugins: [require('autoprefixer')]
}
module.exports = ({ file }) => {
// 组件库设计尺寸是375,所以如果匹配组件库,则将布局尺寸设计成375
const designWidth = file.dirname.includes('node_modules/ppfish-mobile')
? 375
: 750
return {
plugins: {
autoprefixer: {},
'postcss-pxtorem': {
rootValue: designWidth / 10,
propList: ['*']
}
}
}
}
import 'amfe-flexible'
1. npm i http-proxy-middleware@2.0.0
2021.7.18日测试,大于这个版本代理无法成功
const proxy = require('http-proxy-middleware')
module.exports = function (app) {
app.use(
proxy.createProxyMiddleware('/api', {
// 'qwl' 需要转发的请求
target: 'http://localhost:8866', //接口服务器地址
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}),
proxy.createProxyMiddleware('/test', {
target: 'http://localhost:8866',
changeOrigin: true,
pathRewrite: {
'^/test': ''
}
})
)
}
yarn add babel-plugin-import @craco/craco
import IfComp from 'if-comp'
const InnerIfComp = () => (
<IfComp
expression={router.pathname === '/'} //条件
trueComp={<h3>render true component</h3>} //渲染真值内容
falseComp={<h3>render false component</h3>} //渲染假值内容
/>
)
function createMarkup() {
let tempValue = '你好'
let html = `<input value="${tempValue}" ></input>`
return { __html: html }
}
function Example9() {
return (
<>
<div dangerouslySetInnerHTML={createMarkup()} />
</>
)
}
<div
contentEditable="true"
suppressContentEditableWarning="true"
id="test"
></div>