Joe*_*oeH 11 rollup vue.js vite
以下是我的问题。我通过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" },
},
],
},
},
});
Run Code Online (Sandbox Code Playgroud)
最后我解决了我的问题,在 vite.config.js 中添加以下内容。这个对我有用。
build: {
/** If you set esmExternals to true, this plugins assumes that
all external dependencies are ES modules */
commonjsOptions: {
esmExternals: true
},
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27953 次 |
| 最近记录: |