不飞则已,一飞冲天;不鸣则已,一鸣惊人。这篇文章主要讲述???create-react-app???react??????????????????css相关的知识,希望能为你提供帮助。
?????????round
xbox
ref
row
??????
external
??????
??????
resolve
?????????webpack?????????????????????css?????????????????????????????????????????????????????????????????????css??????vue??????????????????style?????????scope???????????????create-react-app???react?????????????????????????????????style???
??????style-loader????????????css
?????????????????????style-loader???modules???????????????webpack?????? ?????????????????? ???????????????
npm run eject
????????????
// config >
webpack.config.dev.js// style files regexes
const cssRegex = /.css$/;
const useable = /.use(able)?.css$/;
// ?????? ??????css
const cssModuleRegex = /.module.css$|.use(able)?.css$/;
{
test: cssRegex,
exclude: cssModuleRegex,
use: getStyleLoaders({
importLoaders: 1,
modules: true// ???????????????
}),
},
css ???????????????????????????????????????????????????use.css??????useable.css??????????????????
//style.use.css
.box {
background: red;
}
???????????????
import React, {Component} from ???react???;
import style from ???./style.use.css???export default class Test extends Component {
render() {
return(
<
div className = {style.box}>
<
div>
{????????????}
<
/div>
<
/div>
)
}
}
【???create-react-app???react??????????????????css】??????class??????????????????????????????????????????????????????????????????????????????????????????css???
文章图片
????????????????????????????????????????????????????????????????????????????????????style?????????????????????????????????,???style?????????????????????????????????????????????????????????style
?????????????????????webpack?????? ?????????????????? ???????????????
npm run eject
// config >
webpack.config.dev.js????????????
// style files regexes
const cssRegex = /.css$/;
const useable = /.use(able)?.css$/;
// ?????? ??????css
const cssModuleRegex = /.module.css$|.use(able)?.css$/;
// ????????????getUseableLoaders
const getUseableLoaders = (cssOptions, preProcessor) =>
{
const loaders = [
require.resolve(???style-loader/useable???),
{
loader: require.resolve(???css-loader???),
options: cssOptions,
},
{
// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
loader: require.resolve(???postcss-loader???),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: ???postcss???,
plugins: () =>
[
require(???postcss-flexbugs-fixes???),
require(???postcss-preset-env???)({
autoprefixer: {
flexbox: ???no-2009???,
},
stage: 3,
}),
],
},
},
];
if (preProcessor) {
loaders.push(require.resolve(preProcessor));
}
return loaders;
};
...
...
{
test: cssRegex,
exclude: cssModuleRegex,
use: getStyleLoaders({
importLoaders: 1,
}),
},
{ // ??????loader
test: useable,
exclude: cssModuleRegex,
use: getUseableLoaders({
importLoaders: 1,
}),
},
...
...
css ???????????????????????????????????????????????????use.css??????useable.css??????????????????
//style.use.css
.box {
background: red;
}
???????????????
import React, {Component} from ???react???;
import style from ???./style.use.css???export default class Test extends Component {
render() {
return(
<
div className = ???box???>
<
div>
{????????????}
<
/div>
<
/div>
)
}
}
???????????????????????????????????? style.use.css ???????????????
推荐阅读
- Android-SQLiteOpenHelper里增删改查
- How to extract WeChat chat messages from a smartphone running Android 7.x or above
- Spring Security(三十七)(Part IV. Web Application Security)
- APICloud之封装webApp
- 8种监视和调试无服务器应用程序的最佳工具
- 10个在线学习DevOps的课程推荐
- 如何在Google Cloud上创建负载均衡器()
- 如何找到Google Cloud VM的外部IP()
- 无服务器计算成为新兴技术的7种方式