赞
踩
npx create-react-app myreact
npm install react-app-rewired customize-cra --save-dev
npm install react-router-dom --save
npm install node-sass --save-dev
npm install classnames --save
const {override,addWebpackAlias,useEslintRc} = require('customize-cra')
const path = require('path')
module.exports = override(
addWebpackAlias({
'@': path.resolve(__dirname, 'src/'),
}),
useEslintRc()
)
{
"extends": "react-app",
"rules": {
"no-undef": "off",
"no-restricted-globals": "off",
"no-unused-vars": "off",
"eqeqeq": "off"
}
}
"scripts": {
"dev": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject"
}
npm run dev
import {HashRouter} from 'react-router-dom'
<HashRouter><App /></HashRouter>
import {Route,Switch,Link,NavLink} from 'react-router-dom'
import routes from './routes.js'
<Switch>
{
routes.map(e => <Route {...e} />)
}
</Switch>
import React, {Component} from 'react'
import classnames from 'classnames'
import './index.scss'
import styles from './index.module.scss'
export default 组件名
npm install @babel/plugin-proposal-decorators --save-dev
addDecoratorsLegacy()
npm install antd-mobile --save
npm install babel-plugin-import --save-dev
fixBabelImports('import', {
libraryName: 'antd-mobile',
style: 'css',
})
npm install axios --save
import axios from 'axios' import {Toast} from 'antd-mobile' axios.interceptors.request.use(function(config){ Toast.loading('加载中') return config }, function (error) { return Promise.reject(error) }); axios.interceptors.response.use(function(response){ Toast.hide() return response.data }, function (error) { return Promise.reject(error) }) export default axios
const commonUrl = `http://${process.env.NODE_ENV == 'development' ? 'localhost' : 'xiaobulaoshi.club'}:8888`
npm install http-proxy-middleware --save-dev
const proxy = require('http-proxy-middleware') module.exports = function(app){ app.use( proxy( '/xiaobu/api', { target: 'http://localhost:8888', secure: false, changeOrigin: true, pathRewrite: { '^/xiaobu/api': '' } } ) ) }
config.url = '/xiaobu/api' + config.url
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。