[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 ...
随机推荐
- iview table 已选项的数据 this.$refs.tables.$refs.tablesMain.getSelection()
iview table 已选项的数据 this.$refs.tables.$refs.tablesMain.getSelection() 由于我这里table组件是套了两层组件 所以是进入了两个层次拿 ...
- syntax error : missing ';' before identifier
原文解决方案 #include "string.h" #include "stdafx.h" #include "Chapter 01 MyVersi ...
- Oracle清空数据库中数据表数据的方法
一.简介最近在项目发版测试的时候,导出dmp的时候不小心把开发库中的一些脏数据导出来了,测试那边导入进去之后一堆不规范的数据,为了不影响测试结果,于是总结了一个快速清空数据库数据表所有数据的方法. 二 ...
- 第一个WebDriver脚本
1.cmd下安装selenium,输入pip install selenium 2.下载Firefox浏览器的驱动程序,https://github.com/mozilla/geckodriver/r ...
- luogu P3916 图的遍历
P3916 图的遍历 题目描述 给出 N 个点, M 条边的有向图,对于每个点 v ,求 A(v) 表示从点 v 出发,能到达的编号最大的点. 输入输出格式 输入格式: 第1 行,2 个整数 N,MN ...
- Linux修改网卡名
问题现象:戴尔机器网卡名为em1,修改为eth0a)由于未发现有/etc/udev/rule.d/70-persistent-net.rules文件,重启后也未发现此文件手动执行/lib/udev/w ...
- MongoDB中导入数据命令的使用(mongoimport)
MongoDB中导入数据命令的使用(mongoimport) 制作人:全心全意 语法: mongoimport <options> <file> 介绍: 该命令可以将CSV,T ...
- js 异步编程方案
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise http://www. ...
- /etc/rc.d启动目录详解
操作系统:CentOS6.6_32位 控制脚本目录/etc/rc.d,该目录下存在各个运行级别的脚本文件,执行ls /etc/rc.d,显示结果为:init.d rc rc0.d rc1.d ...
- 对于easyui $.messager.alert和 $.messager.confirm 不同浏览器中位置控制
$.messager.confirm({ title: '种子购买', msg: '确定购买这个'+seedName+'的种子嘛?', top:, fn: function (r) { if (r){ ...