Skip to content

Commit 1c69539

Browse files
committed
chore: properly externalize react
1 parent 30c3e57 commit 1c69539

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
"@commitlint/config-conventional": "^18.4.3",
134134
"@emoji-mart/data": "^1.1.2",
135135
"@emoji-mart/react": "^1.1.1",
136+
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
136137
"@ladle/react": "^0.16.0",
137138
"@playwright/test": "^1.42.1",
138139
"@semantic-release/changelog": "^6.0.2",

Diff for: scripts/bundle.mjs

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { dirname, resolve } from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import * as esbuild from 'esbuild';
6+
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
67

78
// import.meta.dirname is not available before Node 20
89
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -44,6 +45,27 @@ const browserBundleConfig = {
4445
bundle: true,
4546
format: 'iife',
4647
external: ['react', 'react-dom', 'stream-chat'],
48+
plugins: [
49+
globalExternals({
50+
react: {
51+
varName: 'React',
52+
type: 'cjs',
53+
},
54+
'react/jsx-runtime': {
55+
varName: 'React',
56+
type: 'cjs',
57+
},
58+
'react-dom': {
59+
varName: 'ReactDOM',
60+
type: 'cjs',
61+
},
62+
'stream-chat': {
63+
varName: 'StreamChat',
64+
type: 'cjs',
65+
},
66+
}),
67+
],
68+
globalName: 'StreamChatReact',
4769
outfile: resolve(outDir, 'browser.full-bundle.js'),
4870
sourcemap: 'linked',
4971
};

Diff for: src/index_UMD.ts

+16
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ export * from './i18n';
66
export * from './utils';
77
export { getChannel } from './utils/getChannel';
88
export * from './components/Emojis';
9+
10+
declare global {
11+
interface Window {
12+
Channel: typeof import('stream-chat').Channel;
13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14+
ICAL: any;
15+
logChatPromiseExecution: typeof import('stream-chat').logChatPromiseExecution;
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17+
StreamChat: typeof import('stream-chat') & { StreamChat: any };
18+
}
19+
}
20+
21+
window.StreamChat.StreamChat = window.StreamChat;
22+
window.StreamChat.logChatPromiseExecution = window.logChatPromiseExecution;
23+
window.StreamChat.Channel = window.Channel;
24+
window.ICAL = window.ICAL || {};

Diff for: yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,11 @@
14241424
minimatch "^3.0.4"
14251425
strip-json-comments "^3.1.1"
14261426

1427+
"@fal-works/esbuild-plugin-global-externals@^2.1.2":
1428+
version "2.1.2"
1429+
resolved "https://registry.yarnpkg.com/@fal-works/esbuild-plugin-global-externals/-/esbuild-plugin-global-externals-2.1.2.tgz#c05ed35ad82df8e6ac616c68b92c2282bd083ba4"
1430+
integrity sha512-cEee/Z+I12mZcFJshKcCqC8tuX5hG3s+d+9nZ3LabqKF1vKdF41B92pJVCBggjAGORAeOzyyDDKrZwIkLffeOQ==
1431+
14271432
"@gar/promisify@^1.1.3":
14281433
version "1.1.3"
14291434
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"

0 commit comments

Comments
 (0)