gpt4 book ai didi

reactjs - 如何在 ViteJS 和 React 中使用 autoprefixer?

转载 作者:行者123 更新时间:2023-12-05 03:27:44 42 4
gpt4 key购买 nike

我将 React 与 ViteJS 和 SASS 一起使用,但我遇到了问题。当我构建项目时,似乎没有 CSS/SCSS 的自动前缀。

如何使用 ViteJS 和 SASS 添加自动前缀?

最佳答案

添加postcssautoprefixer:yarn add -D postcss@latest autoprefixer@latest

然后在您的根项目目录中添加一个文件postcss.config.js:

module.exports = {
plugins: {
autoprefixer: {}
}
}

ℹ️ 您可以在下面找到一个没有 postcss 配置文件的新项目的 vite.config.ts 示例。

import { defineConfig } from "vite"
import react from '@vitejs/plugin-react'
import autoprefixer from 'autoprefixer'

export default defineConfig({
plugins: [
react()
],
css: {
postcss: {
plugins: [
autoprefixer({}) // add options if needed
],
}
}
})

如果它仍然不起作用,请提供一个可重现的项目。

关于reactjs - 如何在 ViteJS 和 React 中使用 autoprefixer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71415014/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com