Skip to content

Commit 88aaee3

Browse files
Copilothotlong
andcommitted
Align crm-app MSW setup with todo-app pattern and improve vite config
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent e1724b8 commit 88aaee3

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

examples/crm-app/src/main.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Main Entry Point
3+
*
4+
* Initializes MSW and renders the CRM application.
5+
*/
6+
17
import React from 'react';
28
import ReactDOM from 'react-dom/client';
39
import App from './App';
@@ -8,10 +14,8 @@ import { initClient } from './client';
814

915
async function bootstrap() {
1016
// 1. Start MSW Mock Server (Critical: Must be first)
11-
if (process.env.NODE_ENV === 'development') {
12-
console.log('🛑 Bootstrapping Mock Server...');
13-
await startMockServer();
14-
}
17+
console.log('🛑 Bootstrapping Mock Server...');
18+
await startMockServer();
1519

1620
// 2. Initialize Clients (Must happen AFTER MSW is ready)
1721
// This ensures discovery requests (/api/v1/metadata) are intercepted by MSW

examples/crm-app/vite.config.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@ export default defineConfig(({ mode }) => ({
2525
'@object-ui/example-crm': path.resolve(__dirname, '../../examples/crm/src'),
2626
},
2727
},
28+
optimizeDeps: {
29+
include: [
30+
'msw',
31+
'msw/browser',
32+
'@objectstack/spec',
33+
'@objectstack/spec/data',
34+
'@objectstack/spec/system',
35+
'@objectstack/spec/ui'
36+
]
37+
},
38+
build: {
39+
commonjsOptions: {
40+
include: [/node_modules/, /packages/],
41+
transformMixedEsModules: true
42+
},
43+
rollupOptions: {
44+
onwarn(warning, warn) {
45+
// Suppress warnings for optional dynamic imports
46+
if (
47+
warning.code === 'UNRESOLVED_IMPORT' &&
48+
warning.message.includes('@objectstack/driver-memory')
49+
) {
50+
return;
51+
}
52+
warn(warning);
53+
}
54+
}
55+
},
2856
test: {
2957
globals: true,
3058
environment: 'jsdom',

examples/msw-todo/src/main.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import ReactDOM from 'react-dom/client';
99
import { App } from './App';
1010
import { startMockServer } from './mocks/browser';
1111

12-
// Start MSW before rendering the app
1312
async function bootstrap() {
1413
// Initialize Mock Service Worker
1514
await startMockServer();
@@ -22,4 +21,7 @@ async function bootstrap() {
2221
);
2322
}
2423

25-
bootstrap();
24+
bootstrap().catch(err => {
25+
console.error("FATAL: Application failed to start", err);
26+
document.body.innerHTML = `<div style="color:red; padding: 20px;"><h1>Application Error</h1><pre>${err.message}</pre></div>`;
27+
});

0 commit comments

Comments
 (0)