Skip to content

Commit a6ec7c1

Browse files
committed
feat: add browser mock implementation for chokidar and process environment
1 parent 93b2a06 commit a6ec7c1

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// No-op for browser mocks
2+
export default {};
3+
export const watch = () => ({ on: () => {}, close: () => {} });
4+
export const promises = {};
5+
export const constants = {};
6+
export const readFileSync = () => '';
7+
export const statSync = () => ({ isFile: () => false, isDirectory: () => false });
8+
export const existsSync = () => false;
9+
export const join = (...args: string[]) => args.join('/');
10+
export const resolve = (...args: string[]) => args.join('/');
11+
export const dirname = () => '';
12+
export const basename = () => '';
13+
export const extname = () => '';
14+
export const inspect = () => '';
15+
export const inherits = () => {};
16+
export const EventEmitter = class { on() {} emit() {} };
17+
export const platform = 'browser';
18+
export const cwd = () => '/';
19+
export const env = {};

examples/app-react-crud/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ export default defineConfig({
2626
'os': path.resolve(__dirname, './mocks/node-polyfills.ts'),
2727
'crypto': path.resolve(__dirname, './mocks/node-polyfills.ts'),
2828
'url': path.resolve(__dirname, './mocks/node-polyfills.ts'),
29+
// Fix for chokidar in browser
30+
'chokidar': path.resolve(__dirname, './src/mocks/noop.ts'),
2931
}
3032
},
33+
define: {
34+
'process.env': {},
35+
'process.cwd': '() => "/"',
36+
'process.platform': '"browser"'
37+
},
3138
plugins: [react()],
3239
server: {
3340
port: 3000,

0 commit comments

Comments
 (0)