Skip to content

Commit

Permalink
fix(ui): avoid bundling injectionKeys in custom components
Browse files Browse the repository at this point in the history
The custom component built using `npm run custom.build` was not working
correctly because the `provide/inject` failed.

The error was, we bundled `injectionKeys` in the `template.umd.js` , So
it makes defining two different `Symbol` which point to a different
`provide`.

It's because the `rollupOptions.external` in Vite config pointed to
`../injectionKeys`, but we sometime use the alias `@/injectionKeys`. So
I simply use `path.resolve` to be sure `injectionKeys` are not bundled
in custom components.
  • Loading branch information
madeindjs committed Jan 3, 2025
1 parent 4e956b1 commit 3d53c9c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ui/vite.config.custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { defineConfig, UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import writerPlugin from "./viteWriterPlugin";

const injectionKeys = path.resolve("src/injectionKeys");

export default defineConfig({
base: "./",
plugins: [vue(), writerPlugin()],
Expand All @@ -29,11 +31,11 @@ export default defineConfig({
},
},
rollupOptions: {
external: ["vue", "../injectionKeys"],
external: ["vue", injectionKeys],
output: {
globals: {
vue: "vue",
[path.resolve("src/injectionKeys")]: "injectionKeys",
[injectionKeys]: "injectionKeys",
},
},
},
Expand Down

0 comments on commit 3d53c9c

Please sign in to comment.