[React] {svg, css module, sass} support in Create React App 2.0
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的更多相关文章
- [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 ...
- React使用css module和className多类名设置
引入样式文件 import styles from './footer.module.css'; 注意: 样式文件名必须要以.module.css结尾 单类名设置 <div className= ...
- 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 ...
- React项目中 使用 CSS Module
安装react-app-rewired 由于新的 react-app-rewired@2.x 版本的关系,还需要安装 customize-cra.但是我们这里不需要安装 react-app-rewir ...
- 使用create react app教程
This project was bootstrapped with Create React App. Below you will find some information on how to ...
- 深入 Create React App 核心概念
本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...
- react看这篇就够了(react+webpack+redux+reactRouter+sass)
本帖将对一下内容进行分享: 1.webpack环境搭建: 2.如何使用react-router: 3.引入sass预编译: 4.react 性能优化方案: 5.redux结合react使用: 6.fe ...
- Create React App 安装less 报错
执行npm run eject 暴露模块 安装 npm i less less-loader -D 1.打开 react app 的 webpack.config.js const sassRege ...
- 2019最新create-react-app创建的react中使用sass/scss,以及在react中使用sass/scss公共变量的方法
Sass(英文全称:Syntactically Awesome Stylesheets)是一个最初由Hampton Catlin设计并由Natalie Weizenbaum开发的层叠样式表语言.Sas ...
随机推荐
- Java集合(五)--LinkedList源码解读
首先看一下LinkedList基本源码,基于jdk1.8 public class LinkedList<E> extends AbstractSequentialList<E> ...
- Hadoop-01 搭建hadoop伪分布式运行环境
Linux中配置Hadoop运行环境 程序清单 VMware Workstation 11.0.0 build-2305329 centos6.5 64bit jdk-7u80-linux-x64.r ...
- avalon转成Vue
需求: 旧项目中有部分页面是用avalon写的,avalon存在页面刷新,会出现重复行的问题,数组渲染出现重复行bug, 需要转成vue 总结 记录了一下大概需要改的地方 1. avalon中的ms- ...
- node如何导出数据成为excel格式
node的应用方式,导出数据 首先,你要把数据库连接上,把你要导的数据表写出来 安装模块 $ npm install sequelize $ npm install mysql $ npm insta ...
- vs编译应用程序不依赖运行vs环境
控制台应用程序不依赖VS运行环境就可以运行的设置: 1,使用release模式编译 2,项目属性中,“C/C++”,“代码生成”中的运行库改为“多线程(/MT)” 3,项目属性中,“链接器”,“系统” ...
- python:端口扫描邮件推送
#!/usr/bin/env python import pickle import smtplib from email.mime.text import MIMEText import nmap ...
- Android 图片设置圆角 方法之二
Android中经常会遇到对图片进行二次处理,例如加圆角,或者显示圆形图片.接下来我们再介绍一种方法. 首先, 自定义ImageView: android:id="@+id/iv" ...
- 杭电 1596 find the safest road (最小路径变形求最大安全度)
Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的 ...
- 一道在CF上WA了9次才AC的A题题目与10个版本的代码代码
题目(题目链接:https://codeforces.com/problemset/problem/733/A): A. Grasshopper And the String time limit ...
- pispice中pispice文件夹下模型的描述
VPULSE: 利用PSpice进行仿真时,用VPULSE产生方波,VPULSE在SOURSE库中,有七个参数: V1:低电平,如-5V: V2:高电平,如+5V: TD:第一个脉冲相对于0时刻的延迟 ...