一、创建一个react项目
create-react-app maqiu_admin
cd maqiu_admin
npm start
npm run eject
* ###5添加如下代码
"homepage":".",
二、安装less,配置项目
cnpm install less less-loader --save
-
2 配置config/webpack.config.js
image.png
//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框架
cnpm install -D antd --save
-
2 安装 babel-plugin-import,按需加载antd
cnpm install babel-plugin-import --save
image.png
"plugins":[
[
"import",
{
"librayName":"antd",
"style":true
}
]
]
网友评论