npm install -g webpack
複製代碼
npm install -g create-react-app
複製代碼
npx create-react-app my-app (npxs是npm 5.2+ 附帶的包運行工具)
cd my-app
npm start
複製代碼
到此咱們的react項目就搭建起來了 css
3. 打開package.json,咱們發現不少安裝的依賴並無顯示在package.json中npm run eject
複製代碼
將會把全部內建的配置暴露出來。html
cnpm i -S react-router-dom
複製代碼
const cssRegex = /\.css/;
const cssModuleRegex = /\.module\.css$/;
const sassRegex = /\.(scss|sass)$/;
const sassModuleRegex = /\.module\.(scss|sass)$/;
複製代碼
cnpm i -S less less-loader
複製代碼
const cssRegex = /\.css/; => const cssRegex = /\.css|less/;
複製代碼
在loader配置部分加入:
{
loader: require.resolve('less-loader')
}
複製代碼
yarn add antd 或者 npm install -S antd
複製代碼
import React, { Component } from 'react';
import './index.less';
+ import Button from 'antd/lib/button';
export default class Home extends Component {
render() {
return (
<div className="home_page container">
<h1 className="home_page_title">this is a home pages</h1>
<div className="main_content">
+ <Button type="primary">Login</Button>
+ <Button>go to console</Button>
</div>
</div>
)
}
}
複製代碼
@import '~antd/dist/antd.css';
複製代碼
['import', { libraryName: 'antd', libraryDirectory: 'es', style: 'css' }]
複製代碼
import Button from 'antd/lib/button'; => import { Button } from 'antd'
複製代碼