kerwin_
kerwin_
  • 发布:2024-08-09 19:27
  • 更新:2024-08-10 13:34
  • 阅读:460

为什么在vite中配置了dcloudio/vite-plugin-uni报webpack的错误

分类:uni-app
// package.json  
{  
    "scripts": {  
        "dev": "vite",  
        "build": "vite build",  
        "serve": "vite preview",  
        "server": "vite"  
    },  
    "devDependencies": {  
        "@dcloudio/uni-cli-i18n": "2.0.2-4020420240722003",  
        "@dcloudio/uni-cli-shared": "2.0.2-4020420240722003",  
        "@dcloudio/vite-plugin-uni": "3.0.0-alpha-3000020210521001",  
        "@iconify-json/tabler": "^1.1.119",  
        "unplugin-auto-import": "^0.17.8",  
        "vite": "^4.5.3",  
        "vite-svg-loader": "^5.1.0"  
    },  
    "dependencies": {  
        "crypto-js": "^4.2.0",  
        "pinia": "^2.2.1",  
        "postcss-loader": "^8.1.1",  
        "vite-plugin-restart": "^0.4.1"  
    }  
}  
// vite.config.js  
import { defineConfig } from 'vite';  
import uni from '@dcloudio/vite-plugin-uni';  
import svgLoader from 'vite-svg-loader';  
import AutoImport from 'unplugin-auto-import/vite';  
import ViteRestart from 'vite-plugin-restart';  

export default defineConfig(({ command, mode }) => {  
  console.log(command, mode, 'Environment Variables:');  
  const apiBaseUrl = mode === 'production' ? process.env.VITE_APP_API_BASEURL_PROD : process.env.VITE_APP_API_BASEURL;  

  const config = {  
    plugins: [  
      uni(),  
      svgLoader(),  
      AutoImport({  
        include: [  
          /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx  
          /\.vue$/,  
          /\.vue\?vue/, // .vue  
        ],  
        imports: ["vue", "uni-app"],  
        dts: "hooks/auto-imports.d.ts",  
      }),  
      ViteRestart({  
        restart: ['vite.config.js'],  
      }),  
    ],  
}  
});  
// main.js  
import App from './App'  
import { createSSRApp } from 'vue'  
import { createPinia } from 'pinia';  
// 引入全局的 SCSS 文件  
import './static/commonScss/common.scss';  
import './static/styles/style.scss';  
// 导入打印配置的工具函数  
import { printViteConfig } from './utils/printViteConfig';  
export function createApp() {  
  const app = createSSRApp(App)  
  app.use(createPinia());  
  // 调用打印函数  
  if (process.env.NODE_ENV === 'development') {  
    printViteConfig();  
  }  
  return {  
    app  
  }  
}  

// 运行小程序时报错  
error during build:  
Error: Cannot find module 'webpack'
2024-08-09 19:27 负责人:无 分享
已邀请:
BFC

BFC

你好,uniapp 版本过低, 用npx @dcloudio/uvm@latest 升级一下

要回复问题请先登录注册