Vite: postcss-px-to-viewport配置橫屏參數(shù)landscape: true報(bào)錯(cuò)postcss.atRule is not a constructor

postcss-px-to-viewport是一款很優(yōu)秀的插件,將px單位轉(zhuǎn)換為視口單位的 (vw, vh, vmin, vmax) 的 PostCSS 插件。

在vite構(gòu)建的項(xiàng)目中,開發(fā)過程中,有個(gè)臨時(shí)需求:將移動(dòng)端頁(yè)面適配到橫屏的自助機(jī)上。

vite中內(nèi)置了postcss,引入插件如下:

css: {
    postcss: {
      plugins: [
        require('autoprefixer'),
        require('postcss-px-to-viewport')({
          unitToConvert: 'px',
          viewportWidth: 375,
          unitPrecision: 3,
          propList: ['*'],
          viewportUnit: 'vw',
          fontViewportUnit: 'vw',
          selectorBlackList: ['ignore-'],
          minPixelValue: 1,
          mediaQuery: false,
          replace: true,
          exclude: [],
          landscape: true,
          landscapeUnit: 'vw',
          landscapeWidth: 750,
        }),
      ],
    },
  },

然而會(huì)報(bào)錯(cuò)如下:

image

查閱資料,發(fā)現(xiàn)postcss版本的問題,將postcss.atRule 改成 postcss.AtRule即可。

方法如下:打開node_modules,找到 postcss-px-to-viewport 插件打開如圖

image

找到下面:

編組 5.png

改成:

編組 6.png

再保存,重新跑一邊即可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容