Skip to content
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

转 web 时 scss 通过 additionalData 引入的全局变量 px 不会被转化为 vw 或 rem #1382

Closed
soulmate126 opened this issue Jan 18, 2024 · 1 comment

Comments

@soulmate126
Copy link

转web时通过 css.loaderOptions.scss.additionalData引入全局变量

// vue.config.js
module.exports = defineConfig({
  css: {
      // sourceMap: true,
      loaderOptions: {
          scss: {
            additionalData: '@import "@/styles/var.scss";'
          }
      }
    }
})
// styles/var.scss
$--fs-xs: 14px;
<!-- ./src/pages/index.mpx -->
<style lang="scss">
.list{
  font-size: $--fs-xs;
}
</style>

输出
image

应改转化为对应的 vw单位

mpx-project-2.9 2.zip

@yandadaFreedom
Copy link
Collaborator

yandadaFreedom commented Jan 23, 2024

样式单位转换需要给 @mpxjs/webpack-plugin 插件配置 transRpxRules 转换规则,输出小程序可以将 px 转成 rpx,输出 web可以将 px 转成 vw, 具体配置可参考 https://mpxjs.cn/api/compile.html#transrpxrules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants