以下是我的问题。 我通过vite以库模式打包了我的项目。每当我的库包含任何第三方 UI 库(例如 vue-loading-overlay)时,就会发生错误。但像 moment.js 这样的其他库就不会有问题。
这是我的vite.config.js,我的配置有问题吗?
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [vue()],
build: {
lib: {
entry: resolve(__dirname, "src/lib.ts"),
name: "my-ui-lib",
fileName: "my-ui-lib",
},
rollupOptions: {
external: ["vue"],
output: [
{
format: "es",
exports: "named",
globals: { vue: "vue" },
},
],
},
},
}); Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
最后我解决了我的问题,在 vite.config.js 中添加以下内容。它对我有用。
build: { /** If you set esmExternals to true, this plugins assumes that all external dependencies are ES modules */ commonjsOptions: { esmExternals: true }, }