weixin / posthtml-px2rem

Change px to rem in HTML inline CSS based on PostHTML
https://www.npmjs.com/package/posthtml-px2rem
46 stars 7 forks source link

出现错误信息 #4

Closed brandonxiang closed 5 years ago

brandonxiang commented 7 years ago
  gulp.src(src + '/**/*.html')
        .pipe(posthtml(posthtmlPx2rem({rootValue: 20, minPixelValue: 2})))

出现错误信息,

 tree.match({tag: 'style'}, function (node) {
             ^

TypeError: tree.match is not a function
    at /Users/xiangweiping103/work/epass/node_modules/posthtml-px2rem/index.js:47:14

但是如果输入一个页面,则不会出错。

brandonxiang commented 7 years ago

我试了一下,不兼容3.0.0版的gulp-posthtml,可以在1.5.2版使用,希望能升级

hzlzh commented 7 years ago

好的我来跟一下

xuCesar commented 6 years ago

尝试升级gulp-posthtml到3.0.0,可惜posthtml-px2rem不兼容,盼望能升级

hzlzh commented 5 years ago
var posthtml = require('gulp-posthtml');
var posthtmlPx2rem = require('posthtml-px2rem');

gulp.src(paths.src.html)
.pipe(posthtml(
    [posthtmlPx2rem({rootValue: 20, minPixelValue: 2})]
))
.pipe(gulp.dest(paths.dist.dir));

这样用就兼容了,需要多加一对中括号

也可以这样

.pipe(gulpif(
        config.supportREM,
        posthtml(
          [ require('posthtml-px2rem')({rootValue: 20,minPixelValue: 2}) ]
        ))
      )
hzlzh commented 5 years ago

@xuCesar @brandonxiang 是新版的 posthtml 的接口语法变化导致的,新版本对于同时使用多个插件的支持度变得更好了,我们这个插件在他们首页也有索引,目前我们团队内部使用一切正常。