我是靠谱客的博主 现代芒果,这篇文章主要介绍react 修改css,react 项目设置css模块化,现在分享给大家,希望可以做个参考。

React 项目设置css模块化

1. 在项目下面的node_modules/react-scripts/config/webpack.config.js文件下面修改.

getStyleLoaders({

importLoaders: 1,

modules: true, // 加上modules为true.

sourceMap: isEnvProduction && shouldUseSourceMap,

})

2.在项目的下建一个文件夹 typings文件夹,并创建文件index.d.ts

加入代码

```

declare module ".png";

declare module ".css";

declare module "*.svg";

```

3.0 修改tsconfig.json文件

{

"compilerOptions": {

"target": "es5",

"lib": [

"dom",

"dom.iterable",

"esnext"

],

"allowJs": true,

"skipLibCheck": true,

"esModuleInterop": true,

"allowSyntheticDefaultImports": true,

"strict": true,

"forceConsistentCasingInFileNames": true,

"module": "esnext",

"moduleResolution": "node",

"resolveJsonModule": true,

"isolatedModules": true,

"noEmit": true,

"jsx": "react"

},

"include": [

"src/**/*",

"typings/**/*"

]

}

主要是新加上

"include": [

"src/**/*",

"typings/**/*" // 主要加上这一句代码。

]

}

最后

以上就是现代芒果最近收集整理的关于react 修改css,react 项目设置css模块化的全部内容,更多相关react内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部