From 238cdf3f818ed13c4a25a6812f89e6ef3bf03f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caio=20Povill=20Galv=C3=A3o?= <78922832+CaioBGalvao@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:09:14 -0300 Subject: [PATCH] Add a core entry point without pusher-js to the wrappers The React, Vue and Svelte wrappers declare pusher-js as an optional peer, but import it unconditionally, so they fail to load without it. The default entry point keeps importing pusher-js and registering it as the default Pusher client. The new `core` entry point exports the same API without that import. Both entry points share one chunk, and with it one Echo instance. Co-Authored-By: Claude Opus 5.5 --- packages/react/README.md | 24 ++++++++++++++ packages/react/package.json | 6 ++++ packages/react/src/config/index.ts | 20 ++++++++++-- packages/react/src/config/pusher.ts | 4 +++ packages/react/src/core.ts | 14 ++++++++ packages/react/src/index.iife.ts | 2 ++ packages/react/src/index.ts | 17 ++-------- packages/react/tests/core.test.ts | 49 ++++++++++++++++++++++++++++ packages/react/vite.config.ts | 7 +++- packages/svelte/README.md | 24 ++++++++++++++ packages/svelte/package.json | 6 ++++ packages/svelte/src/config/index.ts | 20 ++++++++++-- packages/svelte/src/config/pusher.ts | 4 +++ packages/svelte/src/core.ts | 14 ++++++++ packages/svelte/src/index.iife.ts | 2 ++ packages/svelte/src/index.ts | 17 ++-------- packages/svelte/tests/core.test.ts | 49 ++++++++++++++++++++++++++++ packages/svelte/vite.config.ts | 7 +++- packages/vue/README.md | 24 ++++++++++++++ packages/vue/package.json | 5 +++ packages/vue/src/config/index.ts | 20 ++++++++++-- packages/vue/src/config/pusher.ts | 4 +++ packages/vue/src/core.ts | 14 ++++++++ packages/vue/src/index.iife.ts | 2 ++ packages/vue/src/index.ts | 17 ++-------- packages/vue/tests/core.test.ts | 49 ++++++++++++++++++++++++++++ packages/vue/vite.config.ts | 7 +++- 27 files changed, 377 insertions(+), 51 deletions(-) create mode 100644 packages/react/src/config/pusher.ts create mode 100644 packages/react/src/core.ts create mode 100644 packages/react/tests/core.test.ts create mode 100644 packages/svelte/src/config/pusher.ts create mode 100644 packages/svelte/src/core.ts create mode 100644 packages/svelte/tests/core.test.ts create mode 100644 packages/vue/src/config/pusher.ts create mode 100644 packages/vue/src/core.ts create mode 100644 packages/vue/tests/core.test.ts diff --git a/packages/react/README.md b/packages/react/README.md index 14b12d58b..ff54c394d 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -38,6 +38,30 @@ configureEcho({ }); ``` +### Without `pusher-js` + +The default entry point imports `pusher-js` and uses it as the Pusher client for the Pusher-based broadcasters. If your application uses another broadcaster, such as Mercure, Socket.IO or the null broadcaster, import from `@laravel/echo-react/core` instead, so `pusher-js` doesn't need to be installed: + +```ts +import { configureEcho, useEcho } from "@laravel/echo-react/core"; + +configureEcho({ + broadcaster: "mercure", +}); +``` + +The `core` entry point exports the same API. To use a Pusher-based broadcaster with it, pass the client yourself: + +```ts +import Pusher from "pusher-js"; +import { configureEcho } from "@laravel/echo-react/core"; + +configureEcho({ + broadcaster: "reverb", + Pusher, +}); +``` + ## Connection Status You can get the current WebSocket connection status using the `useConnectionStatus` hook or the `echo().connectionStatus()` utility function. diff --git a/packages/react/package.json b/packages/react/package.json index 8a977aef7..4b2e274ee 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -71,6 +71,12 @@ "react-native": "./dist/index.common.js", "import": "./dist/index.js", "require": "./dist/index.common.js" + }, + "./core": { + "types": "./dist/core.d.ts", + "react-native": "./dist/core.common.js", + "import": "./dist/core.js", + "require": "./dist/core.common.js" } }, "files": [ diff --git a/packages/react/src/config/index.ts b/packages/react/src/config/index.ts index 276cafde3..1b770b2f4 100644 --- a/packages/react/src/config/index.ts +++ b/packages/react/src/config/index.ts @@ -3,7 +3,6 @@ import Echo, { type Broadcaster, type EchoOptions, } from "laravel-echo"; -import Pusher from "pusher-js"; import type { ConfigDefaults } from "../types"; /** @@ -11,8 +10,23 @@ import type { ConfigDefaults } from "../types"; */ type EchoConfig = ConstructorParameters>[0]; +/** + * The Pusher client constructor accepted by the Pusher-based broadcasters. + */ +type PusherClient = NonNullable["Pusher"]>; + let echoInstance: Echo | null = null; let echoConfig: EchoConfig | null = null; +let defaultPusher: PusherClient | null = null; + +/** + * Register the Pusher client used when the configuration does not provide one. + * + * The default entry point registers `pusher-js`; the `core` entry point does not. + */ +export const registerDefaultPusher = (Pusher: PusherClient): void => { + defaultPusher = Pusher; +}; const getEchoInstance = (): Echo => { if (echoInstance) { @@ -25,7 +39,9 @@ const getEchoInstance = (): Echo => { ); } - echoConfig.Pusher ??= Pusher; + if (defaultPusher) { + echoConfig.Pusher ??= defaultPusher; + } echoInstance = new Echo(echoConfig); diff --git a/packages/react/src/config/pusher.ts b/packages/react/src/config/pusher.ts new file mode 100644 index 000000000..b294637b6 --- /dev/null +++ b/packages/react/src/config/pusher.ts @@ -0,0 +1,4 @@ +import Pusher from "pusher-js"; +import { registerDefaultPusher } from "./index"; + +registerDefaultPusher(Pusher); diff --git a/packages/react/src/core.ts b/packages/react/src/core.ts new file mode 100644 index 000000000..1c32b4bf2 --- /dev/null +++ b/packages/react/src/core.ts @@ -0,0 +1,14 @@ +export type { ConnectionStatus } from "laravel-echo"; +export { configureEcho, echo, echoIsConfigured } from "./config/index"; +export { + useChannel, + useConnectionStatus, + useEcho, + useEchoModel, + useEchoNotification, + useEchoPresence, + useEchoPublic, + usePresenceChannel, + usePublicChannel, + useSocketId, +} from "./hooks/use-echo"; diff --git a/packages/react/src/index.iife.ts b/packages/react/src/index.iife.ts index c56e1ccd4..bf5bed6cb 100644 --- a/packages/react/src/index.iife.ts +++ b/packages/react/src/index.iife.ts @@ -1,3 +1,5 @@ +import "./config/pusher"; + export { configureEcho, echo } from "./config/index"; export { useEcho, diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 1c32b4bf2..b1af40d19 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -1,14 +1,3 @@ -export type { ConnectionStatus } from "laravel-echo"; -export { configureEcho, echo, echoIsConfigured } from "./config/index"; -export { - useChannel, - useConnectionStatus, - useEcho, - useEchoModel, - useEchoNotification, - useEchoPresence, - useEchoPublic, - usePresenceChannel, - usePublicChannel, - useSocketId, -} from "./hooks/use-echo"; +import "./config/pusher"; + +export * from "./core"; diff --git a/packages/react/tests/core.test.ts b/packages/react/tests/core.test.ts new file mode 100644 index 000000000..36c7746c1 --- /dev/null +++ b/packages/react/tests/core.test.ts @@ -0,0 +1,49 @@ +import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; + +describe("entry points", () => { + beforeEach(() => { + vi.resetModules(); + vi.doUnmock("pusher-js"); + }); + + it("loads the core entry point without pusher-js", async () => { + vi.doMock("pusher-js", () => { + throw new Error("pusher-js must not be imported"); + }); + + const { configureEcho, echo } = await import("../src/core"); + + configureEcho({ broadcaster: "null" }); + + expect(echo().options.broadcaster).toBe("null"); + expect(echo().options.Pusher).toBeUndefined(); + }); + + it("keeps pusher-js as the default client in the default entry point", async () => { + const { default: Pusher } = await import("pusher-js"); + const { configureEcho, echo } = await import("../src/index"); + + configureEcho({ broadcaster: "reverb", key: "app-key" }); + + expect(echo().options.Pusher).toBe(Pusher); + }); + + it("prefers the Pusher client passed to configureEcho", async () => { + class CustomPusher {} + const { configureEcho, echo } = await import("../src/index"); + + configureEcho({ broadcaster: "null", Pusher: CustomPusher as never }); + + expect(echo().options.Pusher).toBe(CustomPusher); + }); + + it("shares the Echo instance between both entry points", async () => { + const defaultEntry = await import("../src/index"); + const coreEntry = await import("../src/core"); + + defaultEntry.configureEcho({ broadcaster: "null" }); + + expect(coreEntry.echoIsConfigured()).toBe(true); + expect(coreEntry.echo()).toBe(defaultEntry.echo()); + }); +}); diff --git a/packages/react/vite.config.ts b/packages/react/vite.config.ts index b350f4c98..36d1e70b8 100644 --- a/packages/react/vite.config.ts +++ b/packages/react/vite.config.ts @@ -26,6 +26,8 @@ const config: UserConfig = (() => { rollupOptions: { external: ["react", "pusher-js"], output: { + // Both entry points share this chunk, and with it one Echo instance. + chunkFileNames: "[name]-[hash].[format].js", globals: { react: "React", "pusher-js": "Pusher", @@ -68,7 +70,10 @@ const config: UserConfig = (() => { ]), build: { lib: { - entry: resolve(import.meta.dirname, "src/index.ts"), + entry: { + index: resolve(import.meta.dirname, "src/index.ts"), + core: resolve(import.meta.dirname, "src/core.ts"), + }, formats: ["es", "cjs"], fileName: (format, entryName) => { return `${entryName}.${format === "es" ? "js" : "common.js"}`; diff --git a/packages/svelte/README.md b/packages/svelte/README.md index 217866550..b5ac656cf 100644 --- a/packages/svelte/README.md +++ b/packages/svelte/README.md @@ -38,6 +38,30 @@ configureEcho({ }); ``` +### Without `pusher-js` + +The default entry point imports `pusher-js` and uses it as the Pusher client for the Pusher-based broadcasters. If your application uses another broadcaster, such as Mercure, Socket.IO or the null broadcaster, import from `@laravel/echo-svelte/core` instead, so `pusher-js` doesn't need to be installed: + +```ts +import { configureEcho, useEcho } from "@laravel/echo-svelte/core"; + +configureEcho({ + broadcaster: "mercure", +}); +``` + +The `core` entry point exports the same API. To use a Pusher-based broadcaster with it, pass the client yourself: + +```ts +import Pusher from "pusher-js"; +import { configureEcho } from "@laravel/echo-svelte/core"; + +configureEcho({ + broadcaster: "reverb", + Pusher, +}); +``` + ## Connection Status You can get the current WebSocket connection status using the `useConnectionStatus` function or the `echo().connectionStatus()` utility function. diff --git a/packages/svelte/package.json b/packages/svelte/package.json index 141135447..fe5d13f7b 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -66,6 +66,12 @@ "svelte": "./dist/index.js", "import": "./dist/index.js", "require": "./dist/index.common.js" + }, + "./core": { + "types": "./dist/core.d.ts", + "svelte": "./dist/core.js", + "import": "./dist/core.js", + "require": "./dist/core.common.js" } }, "svelte": "./dist/index.js", diff --git a/packages/svelte/src/config/index.ts b/packages/svelte/src/config/index.ts index 470ba7d32..d28eac8ff 100644 --- a/packages/svelte/src/config/index.ts +++ b/packages/svelte/src/config/index.ts @@ -3,7 +3,6 @@ import Echo, { type Broadcaster, type EchoOptions, } from "laravel-echo"; -import Pusher from "pusher-js"; import type { ConfigDefaults } from "../types"; /** @@ -11,8 +10,23 @@ import type { ConfigDefaults } from "../types"; */ type EchoConfig = ConstructorParameters>[0]; +/** + * The Pusher client constructor accepted by the Pusher-based broadcasters. + */ +type PusherClient = NonNullable["Pusher"]>; + let echoInstance: Echo | null = null; let echoConfig: EchoConfig | null = null; +let defaultPusher: PusherClient | null = null; + +/** + * Register the Pusher client used when the configuration does not provide one. + * + * The default entry point registers `pusher-js`; the `core` entry point does not. + */ +export const registerDefaultPusher = (Pusher: PusherClient): void => { + defaultPusher = Pusher; +}; const getEchoInstance = (): Echo => { if (echoInstance) { @@ -25,7 +39,9 @@ const getEchoInstance = (): Echo => { ); } - echoConfig.Pusher ??= Pusher; + if (defaultPusher) { + echoConfig.Pusher ??= defaultPusher; + } echoInstance = new Echo(echoConfig); diff --git a/packages/svelte/src/config/pusher.ts b/packages/svelte/src/config/pusher.ts new file mode 100644 index 000000000..b294637b6 --- /dev/null +++ b/packages/svelte/src/config/pusher.ts @@ -0,0 +1,4 @@ +import Pusher from "pusher-js"; +import { registerDefaultPusher } from "./index"; + +registerDefaultPusher(Pusher); diff --git a/packages/svelte/src/core.ts b/packages/svelte/src/core.ts new file mode 100644 index 000000000..62436ab9c --- /dev/null +++ b/packages/svelte/src/core.ts @@ -0,0 +1,14 @@ +export type { ConnectionStatus } from "laravel-echo"; +export { configureEcho, echo, echoIsConfigured } from "./config/index"; +export { + useChannel, + useConnectionStatus, + useEcho, + useEchoModel, + useEchoNotification, + useEchoPresence, + useEchoPublic, + usePresenceChannel, + usePublicChannel, + useSocketId, +} from "./runes/useEcho"; diff --git a/packages/svelte/src/index.iife.ts b/packages/svelte/src/index.iife.ts index 29c91221d..b668fe7cd 100644 --- a/packages/svelte/src/index.iife.ts +++ b/packages/svelte/src/index.iife.ts @@ -1,3 +1,5 @@ +import "./config/pusher"; + export { configureEcho, echo, echoIsConfigured } from "./config/index"; export { useConnectionStatus, diff --git a/packages/svelte/src/index.ts b/packages/svelte/src/index.ts index 62436ab9c..b1af40d19 100644 --- a/packages/svelte/src/index.ts +++ b/packages/svelte/src/index.ts @@ -1,14 +1,3 @@ -export type { ConnectionStatus } from "laravel-echo"; -export { configureEcho, echo, echoIsConfigured } from "./config/index"; -export { - useChannel, - useConnectionStatus, - useEcho, - useEchoModel, - useEchoNotification, - useEchoPresence, - useEchoPublic, - usePresenceChannel, - usePublicChannel, - useSocketId, -} from "./runes/useEcho"; +import "./config/pusher"; + +export * from "./core"; diff --git a/packages/svelte/tests/core.test.ts b/packages/svelte/tests/core.test.ts new file mode 100644 index 000000000..36c7746c1 --- /dev/null +++ b/packages/svelte/tests/core.test.ts @@ -0,0 +1,49 @@ +import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; + +describe("entry points", () => { + beforeEach(() => { + vi.resetModules(); + vi.doUnmock("pusher-js"); + }); + + it("loads the core entry point without pusher-js", async () => { + vi.doMock("pusher-js", () => { + throw new Error("pusher-js must not be imported"); + }); + + const { configureEcho, echo } = await import("../src/core"); + + configureEcho({ broadcaster: "null" }); + + expect(echo().options.broadcaster).toBe("null"); + expect(echo().options.Pusher).toBeUndefined(); + }); + + it("keeps pusher-js as the default client in the default entry point", async () => { + const { default: Pusher } = await import("pusher-js"); + const { configureEcho, echo } = await import("../src/index"); + + configureEcho({ broadcaster: "reverb", key: "app-key" }); + + expect(echo().options.Pusher).toBe(Pusher); + }); + + it("prefers the Pusher client passed to configureEcho", async () => { + class CustomPusher {} + const { configureEcho, echo } = await import("../src/index"); + + configureEcho({ broadcaster: "null", Pusher: CustomPusher as never }); + + expect(echo().options.Pusher).toBe(CustomPusher); + }); + + it("shares the Echo instance between both entry points", async () => { + const defaultEntry = await import("../src/index"); + const coreEntry = await import("../src/core"); + + defaultEntry.configureEcho({ broadcaster: "null" }); + + expect(coreEntry.echoIsConfigured()).toBe(true); + expect(coreEntry.echo()).toBe(defaultEntry.echo()); + }); +}); diff --git a/packages/svelte/vite.config.ts b/packages/svelte/vite.config.ts index 93183ff5d..5126ff60d 100644 --- a/packages/svelte/vite.config.ts +++ b/packages/svelte/vite.config.ts @@ -79,6 +79,8 @@ const config: UserConfig = (() => { id.startsWith("svelte/") || id === "pusher-js", output: { + // Both entry points share this chunk, and with it one Echo instance. + chunkFileNames: "[name]-[hash].[format].js", globals: (id) => (id === "pusher-js" ? "Pusher" : "Svelte"), }, }, @@ -119,7 +121,10 @@ const config: UserConfig = (() => { ]), build: { lib: { - entry: resolve(import.meta.dirname, "src/index.ts"), + entry: { + index: resolve(import.meta.dirname, "src/index.ts"), + core: resolve(import.meta.dirname, "src/core.ts"), + }, formats: ["es", "cjs"], fileName: (format, entryName) => { return `${entryName}.${format === "es" ? "js" : "common.js"}`; diff --git a/packages/vue/README.md b/packages/vue/README.md index fd3b21eea..fedfc1cdc 100644 --- a/packages/vue/README.md +++ b/packages/vue/README.md @@ -38,6 +38,30 @@ configureEcho({ }); ``` +### Without `pusher-js` + +The default entry point imports `pusher-js` and uses it as the Pusher client for the Pusher-based broadcasters. If your application uses another broadcaster, such as Mercure, Socket.IO or the null broadcaster, import from `@laravel/echo-vue/core` instead, so `pusher-js` doesn't need to be installed: + +```ts +import { configureEcho, useEcho } from "@laravel/echo-vue/core"; + +configureEcho({ + broadcaster: "mercure", +}); +``` + +The `core` entry point exports the same API. To use a Pusher-based broadcaster with it, pass the client yourself: + +```ts +import Pusher from "pusher-js"; +import { configureEcho } from "@laravel/echo-vue/core"; + +configureEcho({ + broadcaster: "reverb", + Pusher, +}); +``` + ## Connection Status You can get the current WebSocket connection status using the `useConnectionStatus` composable or the `echo().connectionStatus()` utility function. diff --git a/packages/vue/package.json b/packages/vue/package.json index 6678fe222..fab40d16b 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -66,6 +66,11 @@ "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.common.js" + }, + "./core": { + "types": "./dist/core.d.ts", + "import": "./dist/core.js", + "require": "./dist/core.common.js" } }, "files": [ diff --git a/packages/vue/src/config/index.ts b/packages/vue/src/config/index.ts index d44cfdaaf..7b215c341 100644 --- a/packages/vue/src/config/index.ts +++ b/packages/vue/src/config/index.ts @@ -3,7 +3,6 @@ import Echo, { type Broadcaster, type EchoOptions, } from "laravel-echo"; -import Pusher from "pusher-js"; import type { ConfigDefaults } from "../types"; /** @@ -11,8 +10,23 @@ import type { ConfigDefaults } from "../types"; */ type EchoConfig = ConstructorParameters>[0]; +/** + * The Pusher client constructor accepted by the Pusher-based broadcasters. + */ +type PusherClient = NonNullable["Pusher"]>; + let echoInstance: Echo | null = null; let echoConfig: EchoConfig | null = null; +let defaultPusher: PusherClient | null = null; + +/** + * Register the Pusher client used when the configuration does not provide one. + * + * The default entry point registers `pusher-js`; the `core` entry point does not. + */ +export const registerDefaultPusher = (Pusher: PusherClient): void => { + defaultPusher = Pusher; +}; const getEchoInstance = (): Echo => { if (echoInstance) { @@ -25,7 +39,9 @@ const getEchoInstance = (): Echo => { ); } - echoConfig.Pusher ??= Pusher; + if (defaultPusher) { + echoConfig.Pusher ??= defaultPusher; + } echoInstance = new Echo(echoConfig); diff --git a/packages/vue/src/config/pusher.ts b/packages/vue/src/config/pusher.ts new file mode 100644 index 000000000..b294637b6 --- /dev/null +++ b/packages/vue/src/config/pusher.ts @@ -0,0 +1,4 @@ +import Pusher from "pusher-js"; +import { registerDefaultPusher } from "./index"; + +registerDefaultPusher(Pusher); diff --git a/packages/vue/src/core.ts b/packages/vue/src/core.ts new file mode 100644 index 000000000..f852286d8 --- /dev/null +++ b/packages/vue/src/core.ts @@ -0,0 +1,14 @@ +export type { ConnectionStatus } from "laravel-echo"; +export { + useChannel, + useConnectionStatus, + useEcho, + useEchoModel, + useEchoNotification, + useEchoPresence, + useEchoPublic, + usePresenceChannel, + usePublicChannel, + useSocketId, +} from "./composables/useEcho"; +export { configureEcho, echo, echoIsConfigured } from "./config/index"; diff --git a/packages/vue/src/index.iife.ts b/packages/vue/src/index.iife.ts index 8010ab3ea..00031bd77 100644 --- a/packages/vue/src/index.iife.ts +++ b/packages/vue/src/index.iife.ts @@ -1,3 +1,5 @@ +import "./config/pusher"; + export { useEcho, useEchoModel, diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index f852286d8..b1af40d19 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -1,14 +1,3 @@ -export type { ConnectionStatus } from "laravel-echo"; -export { - useChannel, - useConnectionStatus, - useEcho, - useEchoModel, - useEchoNotification, - useEchoPresence, - useEchoPublic, - usePresenceChannel, - usePublicChannel, - useSocketId, -} from "./composables/useEcho"; -export { configureEcho, echo, echoIsConfigured } from "./config/index"; +import "./config/pusher"; + +export * from "./core"; diff --git a/packages/vue/tests/core.test.ts b/packages/vue/tests/core.test.ts new file mode 100644 index 000000000..36c7746c1 --- /dev/null +++ b/packages/vue/tests/core.test.ts @@ -0,0 +1,49 @@ +import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; + +describe("entry points", () => { + beforeEach(() => { + vi.resetModules(); + vi.doUnmock("pusher-js"); + }); + + it("loads the core entry point without pusher-js", async () => { + vi.doMock("pusher-js", () => { + throw new Error("pusher-js must not be imported"); + }); + + const { configureEcho, echo } = await import("../src/core"); + + configureEcho({ broadcaster: "null" }); + + expect(echo().options.broadcaster).toBe("null"); + expect(echo().options.Pusher).toBeUndefined(); + }); + + it("keeps pusher-js as the default client in the default entry point", async () => { + const { default: Pusher } = await import("pusher-js"); + const { configureEcho, echo } = await import("../src/index"); + + configureEcho({ broadcaster: "reverb", key: "app-key" }); + + expect(echo().options.Pusher).toBe(Pusher); + }); + + it("prefers the Pusher client passed to configureEcho", async () => { + class CustomPusher {} + const { configureEcho, echo } = await import("../src/index"); + + configureEcho({ broadcaster: "null", Pusher: CustomPusher as never }); + + expect(echo().options.Pusher).toBe(CustomPusher); + }); + + it("shares the Echo instance between both entry points", async () => { + const defaultEntry = await import("../src/index"); + const coreEntry = await import("../src/core"); + + defaultEntry.configureEcho({ broadcaster: "null" }); + + expect(coreEntry.echoIsConfigured()).toBe(true); + expect(coreEntry.echo()).toBe(defaultEntry.echo()); + }); +}); diff --git a/packages/vue/vite.config.ts b/packages/vue/vite.config.ts index 6022103ef..fb3fe1bc4 100644 --- a/packages/vue/vite.config.ts +++ b/packages/vue/vite.config.ts @@ -26,6 +26,8 @@ const config: UserConfig = (() => { rollupOptions: { external: ["vue", "pusher-js"], output: { + // Both entry points share this chunk, and with it one Echo instance. + chunkFileNames: "[name]-[hash].[format].js", globals: { vue: "Vue", "pusher-js": "Pusher", @@ -68,7 +70,10 @@ const config: UserConfig = (() => { ]), build: { lib: { - entry: resolve(import.meta.dirname, "src/index.ts"), + entry: { + index: resolve(import.meta.dirname, "src/index.ts"), + core: resolve(import.meta.dirname, "src/core.ts"), + }, formats: ["es", "cjs"], fileName: (format, entryName) => { return `${entryName}.${format === "es" ? "js" : "common.js"}`;