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

[Bug] umi max 与 tailwindcss 样式冲突 #9565

Closed
TanGuangZhi opened this issue Oct 20, 2022 · 6 comments
Closed

[Bug] umi max 与 tailwindcss 样式冲突 #9565

TanGuangZhi opened this issue Oct 20, 2022 · 6 comments

Comments

@TanGuangZhi
Copy link

What happens?

umi max 与 tailwindcss 样式冲突,比如下面的 button 按钮样式
image

Mini Showcase Repository(REQUIRED)

Please provide a minimal reproduction then upload to your GitHub. 请提供 最小重现,并上传到你的 GitHub 仓库

pnpm dlx create-umi@latest
选择 ant pro

npx max g tailwindcss
成功后选择 umi 示例项目左侧菜单的 CRUD 示例,即可复现

How To Reproduce

https://github.com/TanGuangZhi/ReactLearn

Context

  • Umi Version: 4.0.24
  • Node Version: 16.17.0
  • Platform: macos 12.3
@xiaohuoni
Copy link
Member

tailwindcss 和 antd 一起用,不是要加 tailwindcss 配置吗?主要是 “corePlugins”

/** @type {import('tailwindcss').Config} */
// TODO: content error
module.exports = {
  content: ['./src/**/**/*.tsx'],
  theme: {
    extend: {},
  },
  plugins: [],
  corePlugins: {
    preflight: false,
  },
};

@xiaohuoni xiaohuoni changed the title [Bug] say something [Bug] umi max 与 tailwindcss 样式冲突 Oct 20, 2022
@TanGuangZhi
Copy link
Author

tailwindcss 和 antd 一起用,不是要加 tailwindcss 配置吗?主要是 “corePlugins”

/** @type {import('tailwindcss').Config} */
// TODO: content error
module.exports = {
  content: ['./src/**/**/*.tsx'],
  theme: {
    extend: {},
  },
  plugins: [],
  corePlugins: {
    preflight: false,
  },
};

感谢,按这个配置了 tailwind.config.js 文件,与 ant 冲突的问题解决了。
额外问下:上面这个配置的写法实在 umi 文档里哪部分?我在引入 tailwindcss 时没有注意到有这块文档,谢谢

@xiaohuoni
Copy link
Member

这个配置是 tailwind 的文档。

@Ray-56
Copy link

Ray-56 commented Dec 1, 2022

当我加了 preflight: false, 配置后,默认重置样式就没有了,于是我使用 addBase 加入一些默认重置样式

plugin: [
    plugin(({ addVariant }) => {
      // addVariant('zh-CN', '&[lang="zh-CN"]');
      // addVariant('en-US', '&[lang="en-US"]');
    }),
    // 本意为移除 base 中的部分样式
    // 相关链接 https://stackoverflow.com/questions/71783177/remove-specific-style-from-tailwind-base
    plugin(function ({ addBase, theme }) {
      addBase({
        h1: { fontSize: theme('fontSize.2xl'), background: 'red' },
        h2: { fontSize: theme('fontSize.xl') },
        h3: { fontSize: theme('fontSize.lg') },
      });
      addBase({ '#test': { background: 'red' } });
  })
]

但是在生成的样式中没有 addBase 的样式

@Ray-56
Copy link

Ray-56 commented Dec 1, 2022

当我加了 preflight: false, 配置后,默认重置样式就没有了,于是我使用 addBase 加入一些默认重置样式

plugin: [
    plugin(({ addVariant }) => {
      // addVariant('zh-CN', '&[lang="zh-CN"]');
      // addVariant('en-US', '&[lang="en-US"]');
    }),
    // 本意为移除 base 中的部分样式
    // 相关链接 https://stackoverflow.com/questions/71783177/remove-specific-style-from-tailwind-base
    plugin(function ({ addBase, theme }) {
      addBase({
        h1: { fontSize: theme('fontSize.2xl'), background: 'red' },
        h2: { fontSize: theme('fontSize.xl') },
        h3: { fontSize: theme('fontSize.lg') },
      });
      addBase({ '#test': { background: 'red' } });
  })
]

但是在生成的样式中没有 addBase 的样式

找到问题了,plugin -> plugins

@yc-w-cn
Copy link

yc-w-cn commented Jun 12, 2023

关闭 preflight 以后,可以通过引入 @tailwind base 使用的 modern-normalize.css 文件解决默认样式重置问题

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

4 participants