(九)css分离与图片路径处理

html-css012

(九)css分离与图片路径处理,第1张

这样就可以完美的解决我们提取css的需求。但是官方不建议我们这样做。他们认为CSS就该打包到JS中减少请求数,看需求吧。

然后在 修改最初的module模块下面的rule里面的css规则变成

上面将css分离出来了。但是图片路径可能不太对

这个不是我们想要的。所以我们要用到publicPath来解决。

在处理前我们在webpack.config.js上声明一个对象叫做 website

这里特别注意的就是 IP和端口 是你本机的IP和你配置的端口

然后在output选项中引用这个对象的publicPath属性

针对IE9的CSS只需在相应CSS代码加入只有IE9识别的 \9\0。具体代码如下:

.div{ background-color:#0f0\9\0/* ie9 */ }

其他浏览器写法:

background-color:#f00/*all*/

background-color:#0ff\0/* ie 8/9 */

background-color:#0f0\9\0/* ie9 */

*background-color:#00f/*ie7*/

_background-color:#ff0/*ie6*/

background-color//:#090/*非IE*/

background-color:#900\9/*所有ie*/

}

.test{ /* 1. */\x0d\x0a\x0d\x0a/* color:#09F\0以前是IE8/9, 现在10也支持 */\x0d\x0a\x0d\x0acolor:#09F\0//* 以前是IE8 only, 现在IE9/10也支持. 如要排除IE9需要使用下面的rule重设IE9样式 */\x0d\x0a\x0d\x0a}\x0d\x0a\x0d\x0a@media all and (min-width:0) { /* 2. */\x0d\x0a\x0d\x0a.test{color:red\9}/* IE9 only, 现在IE10也支持 */\x0d\x0a\x0d\x0a/* Ps:老外的方法都是\0,根本没考虑Opera */\x0d\x0a\x0d\x0a}\x0d\x0a\x0d\x0a@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { /* 3. */\x0d\x0a\x0d\x0a .test { color: green} /* IE10+ */\x0d\x0a\x0d\x0a}\x0d\x0a\x0d\x0a:root .test { color:#963\9} /* 以前IE9 only, 现在10也支持, 优先级高于@media, 优先级太高, 尽量少用 */