antfu-collective / vite-ssg

Static site generation for Vue 3 on Vite
MIT License
1.27k stars 129 forks source link

[commonjs--resolver] No known conditions for "./lib" specifier in "element-plus" package #369

Closed ljhym closed 10 months ago

ljhym commented 10 months ago

Describe the bug

image vite.config.js: `import { defineConfig, loadEnv } from "vite"; import vue from "@vitejs/plugin-vue"; import AutoImport from "unplugin-auto-import/vite"; import Components from "unplugin-vue-components/vite"; import { ElementPlusResolver } from "unplugin-vue-components/resolvers"; import { URL, fileURLToPath } from "node:url"; import VueRouter from "unplugin-vue-router/vite"; import { visualizer } from "rollup-plugin-visualizer";

// https://vitejs.dev/config/ export default defineConfig(({ mode }) => { // 根据当前工作目录中的 mode 加载 .env 文件 // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 VITE_ 前缀。 const env = loadEnv(mode, process.cwd(), ""); return { // vite 配置 define: { __APP_ENV__: JSON.stringify(env.APP_ENV) }, base: env.VITE_BASE, plugins: [ VueRouter({ routesFolder: ["src/pages"] }), vue(), AutoImport({ eslintrc: { enabled: true, // 默认false, true启用。生成一次就可以,避免每次工程启动都生成 filepath: "./.eslintrc-auto-import.json", // 生成json文件 globalsPropValue: true }, resolvers: [ElementPlusResolver({ importStyle: "sass", ssr: true })], imports: ["vue", "pinia", "vue-router"], dirs: [ // './src/hooks', "./src/api/", // all nested "./src/utils/", // all nested "./src/components/", "./src/composables/" // all nested ], include: [/.js$/, /.vue$/, /.vue\?vue/], // 设置需要导入的文件类型,检测 dirs 配置的路径的文件 // dts: true, dts: "./auto-imports.d.ts" }), Components({ resolvers: [ElementPlusResolver({ importStyle: "sass", ssr: true })] }), visualizer({ open: true }) ], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), api: fileURLToPath(new URL("./src/api", import.meta.url)), utils: fileURLToPath(new URL("./src/utils", import.meta.url)), store: fileURLToPath(new URL("./src/store", import.meta.url)), pages: fileURLToPath(new URL("./src/pages", import.meta.url)), assets: fileURLToPath(new URL("./src/assets", import.meta.url)), components: fileURLToPath(new URL("./src/components", import.meta.url)), composables: fileURLToPath(new URL("./src/composables", import.meta.url)) } }, server: { // port: 8888, // open: true, proxy: { "^/api": { target: "https://www.miniui.top", // 代理接口地址 changeOrigin: true, cors: true, rewrite: (path) => path.replace(/^\/api/, "") } } }, build: { minify: "terser", terserOptions: { compress: { //生产环境时移除console drop_console: true, drop_debugger: true } }, rollupOptions: { output: { manualChunks: (filePath) => { if (filePath.includes("node_modules")) { return filePath.toString().split("node_modules/")[1].split("/")[0].toString(); } // if (id.includes("element-plus") || id.includes("bootstrap")) { // return; //不打入这俩个文件相关的东西 // } // if (id.includes("Login/")) { // //利用文件目录判断 // console.log( // id.toString().split("Login/")[1].split(".")[0].toString() // ); // return id.toString().split("Login/")[1].split(".")[0].toString(); // } }, chunkFileNames: "static/js/[name]-[hash].js", entryFileNames: "static/js/[name]-[hash].js", assetFileNames: "static/[ext]/[name]-[hash].[ext]" // chunkFileNames: 'static/js/[name].js', // entryFileNames: 'static/js/[name].js', // assetFileNames: 'static/[ext]/[name].[ext]', } } }, ssgOptions: { crittersOptions: { // E.g., change the preload strategy preload: "media" // Other options: https://github.com/GoogleChromeLabs/critters#usage } } }; }); `

Reproduction

https://gitee.com/ljhym/vue3template.git

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i5-10500 CPU @ 3.10GHz
    Memory: 21.47 GB / 31.83 GB
  Binaries:
    Node: 16.15.0 - D:\nvm\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.5.5 - D:\nvm\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (116.0.1938.54)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Validations