@@ -324,12 +324,6 @@ module.exports = (api, options, rootOptions) => {
324
324
// application 应用类型为 mobile
325
325
if ( options . application === 'mobile' || options . application === 'offline' ) {
326
326
api . extendPackage ( {
327
- dependencies : {
328
- 'lib-flexible' : '0.3.2'
329
- } ,
330
- devDependencies : {
331
- 'postcss-pxtorem' : '^4.0.1'
332
- } ,
333
327
postcss : {
334
328
plugins : {
335
329
autoprefixer : {
@@ -340,30 +334,81 @@ module.exports = (api, options, rootOptions) => {
340
334
'ff > 34' ,
341
335
'ie >= 10'
342
336
]
343
- } ,
344
- 'postcss-pxtorem' : {
345
- rootValue : 37.5 ,
346
- unitPrecision : 2 ,
347
- propList : [
348
- 'height' ,
349
- 'line-height' ,
350
- 'width' ,
351
- 'padding' ,
352
- 'margin' ,
353
- 'top' ,
354
- 'left' ,
355
- 'right' ,
356
- 'bottom' ,
357
- 'font-size'
358
- ] ,
359
- selectorBlackList : [ ] ,
360
- replace : true ,
361
- mediaQuery : false ,
362
- minPixelValue : 1
363
337
}
364
338
}
365
339
}
366
340
} ) ;
341
+ // 移动端适配方案
342
+ if ( options [ 'layout-adapter' ] === 'vw' ) {
343
+ api . extendPackage ( {
344
+ devDependencies : {
345
+ 'postcss-px-to-viewport' : '^1.1.1'
346
+ } ,
347
+ postcss : {
348
+ plugins : {
349
+ 'postcss-px-to-viewport' : {
350
+ unitToConvert : 'px' , // 要转化的单位
351
+ viewportWidth : 375 , // UI设计稿的宽度
352
+ unitPrecision : 6 , // 转换后的精度,即小数点位数
353
+ propList : [
354
+ 'height' ,
355
+ 'line-height' ,
356
+ 'width' ,
357
+ 'padding*' ,
358
+ 'margin*' ,
359
+ 'top' ,
360
+ 'left' ,
361
+ 'right' ,
362
+ 'bottom' ,
363
+ 'border*'
364
+ ] , // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
365
+ viewportUnit : 'vw' , // 指定需要转换成的视窗单位,默认vw
366
+ fontViewportUnit : 'vw' , // 指定字体需要转换成的视窗单位,默认vw
367
+ selectorBlackList : [ 'wrap' , '.ignore-' , '.hairlines' ] , // 指定不转换为视窗单位的类名,
368
+ minPixelValue : 1 , // 默认值1,小于或等于1px则不进行转换
369
+ mediaQuery : true , // 是否在媒体查询的css代码中也进行转换,默认false
370
+ replace : true , // 是否转换后直接更换属性值
371
+ exclude : [ / n o d e _ m o d u l e s / ] , // 设置忽略文件,用正则做目录名匹配
372
+ landscape : false , // 是否处理横屏情况,是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
373
+ landscapeUnit : 'vw' , //横屏时使用的单位
374
+ landscapeWidth : 1134 //横屏时使用的视口宽度
375
+ }
376
+ }
377
+ }
378
+ } ) ;
379
+ } else {
380
+ api . extendPackage ( {
381
+ dependencies : {
382
+ 'amfe-flexible' : '2.2.1'
383
+ } ,
384
+ devDependencies : {
385
+ 'postcss-pxtorem' : '^4.0.1'
386
+ } ,
387
+ postcss : {
388
+ plugins : {
389
+ 'postcss-pxtorem' : {
390
+ rootValue : 37.5 ,
391
+ unitPrecision : 2 ,
392
+ propList : [
393
+ 'height' ,
394
+ 'line-height' ,
395
+ 'width' ,
396
+ 'padding' ,
397
+ 'margin' ,
398
+ 'top' ,
399
+ 'left' ,
400
+ 'right' ,
401
+ 'bottom'
402
+ ] ,
403
+ selectorBlackList : [ ] ,
404
+ replace : true ,
405
+ mediaQuery : false ,
406
+ minPixelValue : 1
407
+ }
408
+ }
409
+ }
410
+ } ) ;
411
+ }
367
412
}
368
413
369
414
// application 应用类型为 H5离线包
0 commit comments