-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack2 中开启 CSS-MODULES #4
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
开启
CSS-MODULES
写
CSS
少不了要面对命名冲突、模块依赖、全局污染等问题,目前也有不少解决方法;比如
SASS
LESS
的嵌套写法,VUE
中scoped
关键字都是解决这些问题的;但是在
React
项目中CSS-IN-JS
这种,要怎么处理CSS
一开始很迷糊;最近看到了
CSS-MODULES
这个东西,觉得挺有意思;安利的文章可以看一篇知乎上的专栏:『CSS 模块』 『CSS Modules 详解及 React 中实践』
修改配置
开始
CSS-MODULES
很简单 webpack2中的写法POSTCSS
的配置稍稍有点调整,需要在项目根目录下添加postcss.config.js
配置文件;题外话
在开始引入
autoprefixer
的时候发现并没有起作用然后找了很多文档:webpack2 options are useless #128
Remove Autoprefixer from cssnano #281
大致的问题是之前
css-loader
里面的cssnano
在搞事?编译的时候把autoprefixer
添加的前缀给删了.最终还是看官方配置 postcss/autoprefixer
另一种
CSS-IN-JS
的解决方案这是个
React
的一个第三方库,官方 styled-components
这个应该是一个更全面的解决方案?跨平台?不是很清楚,
RN
没有写过,不过语法上,不是很习惯;最终编译成了
结语
两种解决方案都可行,最终还是看项目需求,和语法习惯了.
The text was updated successfully, but these errors were encountered: