-
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
webpack 中 postcss-px2rem 生产环境中注释失效 #15
Comments
webpack
中 postcss-px2rem
生产环境中注释失效
同样在
依赖文件如下:
然后根据
所以需要在
更改完毕后再次打包生产环境,注释生效,暂时没有发现其他的后遗症。 |
这样设置以后,打包以后的样式文件没有被压缩,应该会导致样式文件的体积变大吧?这个如何解决呢? |
@ 问题
webapp
使用flexible.js
配合postcss
插件做的适配;在开发环境下页面正常显示,但是到生产环境下postcss-px2rem
/*px*/ /*no*/
注释没有起作用;环境
window
webpack
: 3.5.5postcss-loader
: 2.0.8postcss-px2rem
: 0.3.0node-sass
: 4.7.2配置
样式结果
@ 查找解决办法
起初,以为是
webpack
中的UglifyJSPlugin
压缩的时候把注释代码全都去掉了,才引起了postcss-px2rem
/*px*/ /*no*/
等注释不起作用;但是深入查找答案过后,其实并不是
UglifyJSPlugin
在做怪,在sass-loader
选项里配置outputStyle: 'expanded',
是可以解决/*px*/ /*no*/
注释失效的问题;修改配置如下:
@ 深入查找原因
实际的解决办法,不是自己想象
UglifyJSPlugin
压缩引起的原因(假想不去验证,思想太危险);必须得查清楚问题根源;
sass-loader
sass-loader
的配置项里添加配置解决了注释失效问题;sass-loader
github
上去查看官方文档;整片文档看下来并没有
outputStyle
这个配置项,这就奇怪了,难道是黑魔法?翻阅
issue
查找outputStyle
关键字有很多closed issue
这个配置项肯定是存在的;查看源码!
sass-loader/lib/normalizeOptions.js
中找到了选项找到根源了,如果没有配置项,就执行压缩;
node-sass
在
sass-loader
中没有outputStyle: 'expanded',
配置项,想到sass-loader
又是基于node-sass
的;github
上node-sass
的文档中最终找到根源,
outputStyle: 'expanded',
设置sass-loader
解析过后css
文件是可拓展的;@ 参考
webpack-contrib sass-loader
node-sass
px2rem issues#2
sass-loader issues#299
resolve-url-loader issues#57
The text was updated successfully, but these errors were encountered: