Skip to content

Commit cc2818f

Browse files
committed
fix clerk/ui chunks
1 parent fc579c5 commit cc2818f

File tree

3 files changed

+55
-92
lines changed

3 files changed

+55
-92
lines changed

packages/ui/rspack.config.js

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,6 @@ const common = ({ mode, variant }) => {
5353
optimization: {
5454
splitChunks: {
5555
cacheGroups: {
56-
// Component-specific chunks
57-
signUp: {
58-
test: /[\\/]src[\\/]components[\\/]SignUp[\\/]/,
59-
name: 'signup',
60-
chunks: 'all',
61-
priority: 10,
62-
},
63-
signIn: {
64-
test: /[\\/]src[\\/]components[\\/]SignIn[\\/]/,
65-
name: 'signin',
66-
chunks: 'all',
67-
priority: 10,
68-
},
69-
userProfile: {
70-
test: /[\\/]src[\\/]components[\\/]UserProfile[\\/]/,
71-
name: 'user-profile',
72-
chunks: 'all',
73-
priority: 10,
74-
},
75-
organizationProfile: {
76-
test: /[\\/]src[\\/]components[\\/]OrganizationProfile[\\/]/,
77-
name: 'organization-profile',
78-
chunks: 'all',
79-
priority: 10,
80-
},
81-
userButton: {
82-
test: /[\\/]src[\\/]components[\\/]UserButton[\\/]/,
83-
name: 'user-button',
84-
chunks: 'all',
85-
priority: 10,
86-
},
87-
organizationSwitcher: {
88-
test: /[\\/]src[\\/]components[\\/]OrganizationSwitcher[\\/]/,
89-
name: 'organization-switcher',
90-
chunks: 'all',
91-
priority: 10,
92-
},
93-
// Vendor chunks
9456
zxcvbnTSCoreVendor: {
9557
test: /[\\/]node_modules[\\/](@zxcvbn-ts\/core|fastest-levenshtein)[\\/]/,
9658
name: 'zxcvbn-ts-core',
@@ -101,21 +63,35 @@ const common = ({ mode, variant }) => {
10163
name: 'zxcvbn-common',
10264
chunks: 'all',
10365
},
104-
emotionVendor: {
105-
test: /[\\/]node_modules[\\/](@emotion)[\\/]/,
106-
name: 'emotion-vendor',
66+
baseAccountSDKVendor: {
67+
test: /[\\/]node_modules[\\/](@base-org\/account|@noble\/curves|abitype|ox|preact|eventemitter3|viem|zustand)[\\/]/,
68+
name: 'base-account-sdk',
10769
chunks: 'all',
108-
priority: 20,
10970
},
110-
floatingUIVendor: {
111-
test: /[\\/]node_modules[\\/](@floating-ui)[\\/]/,
112-
name: 'floating-ui-vendor',
71+
coinbaseWalletSDKVendor: {
72+
test: /[\\/]node_modules[\\/](@coinbase\/wallet-sdk|preact|eventemitter3|@noble\/hashes)[\\/]/,
73+
name: 'coinbase-wallet-sdk',
11374
chunks: 'all',
11475
},
11576
stripeVendor: {
116-
test: /[\\/]node_modules[\\/](@stripe)[\\/]/,
117-
name: 'stripe-vendor',
77+
test: /[\\/]node_modules[\\/](@stripe\/stripe-js)[\\/]/,
78+
name: 'stripe-vendors',
11879
chunks: 'all',
80+
enforce: true,
81+
},
82+
/**
83+
* Sign up is shared between the SignUp component and the SignIn component.
84+
*/
85+
signUp: {
86+
minChunks: 1,
87+
name: 'signup',
88+
test: module => !!(module.resource && module.resource.includes('/ui/components/SignUp')),
89+
},
90+
common: {
91+
minChunks: 1,
92+
name: 'ui-common',
93+
priority: -20,
94+
test: module => !!(module.resource && !module.resource.includes('/ui/components')),
11995
},
12096
defaultVendors: {
12197
minChunks: 1,
@@ -125,7 +101,7 @@ const common = ({ mode, variant }) => {
125101
},
126102
react: {
127103
chunks: 'all',
128-
test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
104+
test: /[\\/]node_modules[\\/](react-dom|scheduler)[\\/]/,
129105
name: 'framework',
130106
priority: 40,
131107
enforce: true,
@@ -288,7 +264,7 @@ const devConfig = (mode, env) => {
288264
// devtool: 'eval-cheap-source-map',
289265
devtool: false,
290266
output: {
291-
publicPath: `${devUrl.origin}/npm`,
267+
publicPath: `${devUrl.origin}/npm/`,
292268
crossOriginLoading: 'anonymous',
293269
filename: `[name].js`,
294270
libraryTarget: 'umd',

packages/ui/src/index.browser.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
import './utils/setWebpackChunkPublicPath';
2-
3-
console.log('is it gonna run now?');
4-
5-
window.__unstable_ClerkUi = {
6-
hello: true,
7-
};
8-
91
// TODO: @nikos move this to shared utils
102
// It's crucial this is the first import,
113
// otherwise chunk loading will not work
12-
// import './utils/setWebpackChunkPublicPath';
13-
14-
// /**
15-
// * Browser bundle entry point for @clerk/ui
16-
// *
17-
// * This file is built with rspack and exposes the UI components
18-
// * to the global window object for consumption by clerk-js and other packages.
19-
// */
20-
import { mountComponentRenderer } from './Components1';
21-
console.log('nikos mountComponentRenderer', mountComponentRenderer);
4+
import './utils/setWebpackChunkPublicPath';
225

23-
// // Expose to window for external consumption
24-
// console.log('nikos will inect');
6+
/**
7+
* Browser bundle entry point for @clerk/ui
8+
*
9+
* This file is built with rspack and exposes the UI components
10+
* to the global window object for consumption by clerk-js and other packages.
11+
*/
12+
import { mountComponentRenderer } from './Components';
2513

26-
// if (!window.__unstable_ClerkUi) {
27-
// window.__unstable_ClerkUi = {
28-
// mountComponentRenderer,
29-
// version: PACKAGE_VERSION,
30-
// };
31-
// console.log('nikos clerkui injected ', window.__unstable_ClerkUi);
32-
// }
14+
if (!window.__unstable_ClerkUi) {
15+
window.__unstable_ClerkUi = {
16+
mountComponentRenderer,
17+
version: PACKAGE_VERSION,
18+
};
19+
}
3320

3421
// // Hot module replacement for development
3522
// if (module.hot) {

scripts/rspack-common.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ const typescriptLoaderProd = ({ targets, useCoreJs = false } = {}) => {
6969
},
7070
},
7171
},
72-
...(useCoreJs
73-
? [
74-
{
75-
test: /\.m?js$/,
76-
exclude: /node_modules[\\/]core-js/,
77-
use: {
78-
loader: 'builtin:swc-loader',
79-
options: {
80-
env: {
81-
...(targets ? { targets } : {}),
72+
{
73+
test: /\.m?js$/,
74+
exclude: /node_modules[\\/]core-js/,
75+
use: {
76+
loader: 'builtin:swc-loader',
77+
options: {
78+
env: {
79+
...(targets ? { targets } : {}),
80+
...(useCoreJs
81+
? {
8282
mode: 'usage',
8383
coreJs: '3.41.0',
84-
},
85-
isModule: 'unknown',
86-
},
87-
},
84+
}
85+
: {}),
8886
},
89-
]
90-
: []),
87+
isModule: 'unknown',
88+
},
89+
},
90+
},
9191
];
9292
};
9393

0 commit comments

Comments
 (0)