react安装及使用

一, 安装react脚手架

  1. 全局安装脚手架

    npm install -g create-react-app

  2. 创建我们react项目

    npx create-react-app shen-react(项目名不能有大写)

  3. 运行

    cd shen-react

    npm start

二. 安装react路由

  1. 安装react-router-dom

  npm install react-router-dom --save-dev

三, 创建项目中webpack配置文件

  npm run eject

  如果这步报错  运行   git add .          git commit -m 'init'

  然后在运行 npm run eject

四, 安装less

  npm install less less-loader --save-dev 

  建议是用 yarn add less-loader@5.0.0

  修改配置文件 config/webpack.config.js

  

// style files regexes 47行
const cssRegex = /.css$/;
const cssModuleRegex = /.module.css$/;
const sassRegex = /.(scss|sass)$/;
const sassModuleRegex = /.module.(scss|sass)$/;

// 新加
const lessRegex = /.less$/;
const lessModuleRegex = /.module.less$/;
//less 自定义 466行
// 找 sassRegex 并列放在这个对象上面,
{ test: lessRegex, exclude: lessModuleRegex, use: getStyleLoaders({ importLoaders: 3, 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: 3, sourceMap: isEnvProduction && shouldUseSourceMap, modules: { getLocalIdent: getCSSModuleLocalIdent, }, }, 'less-loader' ), }, //less end 自定义

  

原文地址:https://www.cnblogs.com/shenjilin/p/13454490.html