create-react-app version 2.0 added a lot of new features.

One of the new features is added the svgr webpack loader to wrap SVGs in React components as a named export. This let’s you either grab the filename from the default export or grab a wrapped SVG component depending on your needs.

Second of the new features is support for Sass. If you start to use Sass, create-react-app will give you an error, but will give detailed instructions on how you can add Sass support to your project.

Thrid features is to add CSS Module support. CSS Modules automatically scope class names and animation names local by default to get around the problem of global name clashes. You can learn more by looking at the CSS Modules repository.

import React, {Component} from 'react';
// ReactComponent support svg
import logo, {
ReactComponent as ReactLogo
} from "./logo.svg";
import './App.scss';
// Supoort
import styles from './styles.module.css'; class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<!-- Using svg -->
<ReactLogo className="App-logo-svg" alt="logo"/>
<img src={logo} className="App-logo" alt="logo"/>
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<!-- Using css module -->
<a
className={styles['error']}
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
} export default App;

App.scss:

.App-logo-svg {
height: 40vmin;
& g {
fill: salmon;
} & path {
stroke: palegoldenrod;
fill: none;
stroke-width: 10px;
stroke-dasharray: 35px 15px;
animation: orbit 1s infinite linear;
}
} @keyframes orbit { to { stroke-dashoffset: 50px; } }

styles.module.css:

.warning {
color: black;
background-color: yellow;
} .error {
color: white;
background-color: red;
}

[React] {svg, css module, sass} support in Create React App 2.0的更多相关文章

  1. [React] Use the Fragment Short Syntax in Create React App 2.0

    create-react-app version 2.0 added a lot of new features. One of the new features is upgrading to Ba ...

  2. React使用css module和className多类名设置

    引入样式文件 import styles from './footer.module.css'; 注意: 样式文件名必须要以.module.css结尾 单类名设置 <div className= ...

  3. parcel bug & not support normal import React & ReactDOM module

    bug report not support normal import React & ReactDOM module, why Code Sample OK import * as Rea ...

  4. React项目中 使用 CSS Module

    安装react-app-rewired 由于新的 react-app-rewired@2.x 版本的关系,还需要安装 customize-cra.但是我们这里不需要安装 react-app-rewir ...

  5. 使用create react app教程

    This project was bootstrapped with Create React App. Below you will find some information on how to ...

  6. 深入 Create React App 核心概念

    本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...

  7. react看这篇就够了(react+webpack+redux+reactRouter+sass)

    本帖将对一下内容进行分享: 1.webpack环境搭建: 2.如何使用react-router: 3.引入sass预编译: 4.react 性能优化方案: 5.redux结合react使用: 6.fe ...

  8. Create React App 安装less 报错

    执行npm run eject 暴露模块 安装 npm i  less less-loader -D 1.打开 react app 的 webpack.config.js const sassRege ...

  9. 2019最新create-react-app创建的react中使用sass/scss,以及在react中使用sass/scss公共变量的方法

    Sass(英文全称:Syntactically Awesome Stylesheets)是一个最初由Hampton Catlin设计并由Natalie Weizenbaum开发的层叠样式表语言.Sas ...

随机推荐

  1. MFC不同分辨率和缩放下正常显示的方法

    方法1:为了满足Windows操作系统上不同分辨率下的显示,我们在OnPaint中重绘.

  2. oracle函数笔记(1)

    1.在数据库中显示当前时间:函数(sysdate) select sysdate from dual: 2.数据库中显示 :年/月/日 时/分/秒 ---函数:to_char(字段,'yyyy-mm- ...

  3. 转: 使用 /sys 文件系统访问 Linux 内核

    转一个挺不错的文章 使用 /sys 文件系统访问 Linux 内核 https://www.ibm.com/developerworks/cn/linux/l-cn-sysfs/ 如果你正在开发的设备 ...

  4. vue-loader 细节

    vue-loader 能根据 .vue 文件,导入一个vue组件.我这里从 vue-cli 的构建项目中抽取了vue-loader 一个小例子出来:vuedemo/demo02 vue-loader ...

  5. HTML5编辑API之Range对象

    Range对象代表页面上的一段连续区域,通过Range对象,可以获取或修改页面上的任何区域,可以通过如下创建一个空的Range对象,如下: var  range = document.createRa ...

  6. cetos7 安装telnet

    先执行命令 rpm -qa | grep telnet rpm -qa | grep telnet-server rpm -qa | grep xinetd 如果返回空白就是没有安装 yum inst ...

  7. 3. express 框架使用 vue框架 weiUI

    express 1. 安装 npm install express --save 2. 创建项目 vue js 安装Vuejs vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue- ...

  8. 关于对象字面量花括号{} key的类型

    原来对{}方式建立的实例化后的对象的key,理解不清,只知道,数组加不加“”,反正都是字符,现在要理解下,到底怎么回事?返回结果是 var a={}; a[1]="a"; a[&q ...

  9. mq推送消息

    场景:BDM(实名制系统)同步数据到CRNS(实名制系统) 一,首先建个队列,队列名字为 bdm_empolyeeinfo_crns 二,applicationContext-rabbitmq.xml ...

  10. Python+selenium登录测试

    我们以登录新浪微博为案例来讲解,首先进入登录页面,输入用户名和密码,点击登录按钮,并且获得用户信息以验证是否登录成功. Web地址:https://login.sina.com.cn/signup/s ...