react+antd+router完成一个后台
2019-04-18 本文已影响0人
一个被程序员耽误的厨师
一、创建一个react项目
-
1、创建一个react项目
create-react-app maqiu_admin
-
2 验证项目是否创建完成
cd maqiu_admin
npm start
-
3 暴露配置文件
npm run eject
-
4 修改package.json文件
* ###5添加如下代码
"homepage":".",
二、安装less,配置项目
-
1 安装less
cnpm install less less-loader --save
-
2 配置config/webpack.config.js
//less
const lessRegex = /\.less$/;
const lessModuleRegex = /\.module\.less$/;
image.png
if(preProcessor === 'less-loader'){
loaders.push({
loader: require.resolve(preProcessor),
options: {
sourceMap: isEnvProduction && shouldUseSourceMap,
javascriptEnabled:true,
modifyVars:{
"@primary-color":"#1890ff"
}
},
});
}else{
loaders.push({
loader: require.resolve(preProcessor),
options: {
sourceMap: isEnvProduction && shouldUseSourceMap,
},
});
}
image.png
{
test: lessRegex,
exclude: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'less-loader'
),
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
// Remove this when webpack adds a warning or an error for this.
// See https://github.com/webpack/webpack/issues/6571
sideEffects: true,
},
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
{
test: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'less-loader'
),
},
三、项目引入antdesign框架
-
1 安装antd
cnpm install -D antd --save
-
2 安装 babel-plugin-import,按需加载antd
cnpm install babel-plugin-import --save
-
3 修改配置文件package.json
"plugins":[
[
"import",
{
"librayName":"antd",
"style":true
}
]
]