小编Tha*_*han的帖子

如何使用 vite + React 项目添加自动前缀

您好,我使用创建了反应应用程序npm create vite,并尝试集成,autoprefixer但它不起作用。

vite.config.js

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

export default defineConfig({
    plugins: [react()],
    css: {
        postcss: {
            plugins: [autoprefixer()],
        },
    },
});
Run Code Online (Sandbox Code Playgroud)

package.json

  "devDependencies": {
    "@types/react": "^18.0.17",
    "@types/react-dom": "^18.0.6",
    "@vitejs/plugin-react": "^2.1.0",
    "autoprefixer": "^10.4.8",
    "postcss": "^8.4.16",
    "sass": "^1.54.9",
    "vite": "^3.1.0"
  },
  "browserslist": [ "last 2 versions", "not dead" ] 
Run Code Online (Sandbox Code Playgroud)

我尝试创建一个postcss.config.js,但它也不起作用。

postcss.config.js

import autoprefixer from 'autoprefixer';

export const plugins = {
    plugins: [autoprefixer()],
};
Run Code Online (Sandbox Code Playgroud)

如果有人能帮助我那就太好了!

reactjs autoprefixer postcss vite

3
推荐指数
1
解决办法
5045
查看次数

标签 统计

autoprefixer ×1

postcss ×1

reactjs ×1

vite ×1