feat: add universal adapters for browser compatibility
- Create universal adapters for cross-platform support (browser/Node/serverless) - Replace Node.js-specific imports with universal implementations - Add OPFS support for browser persistent storage - Maintain same BrainyData interface across all environments - Enable real Brainy usage in browser console UI - Keep package size optimized (no bloat) Universal adapters in /src/universal/: - uuid.ts: Cross-platform UUID generation - crypto.ts: Browser/Node crypto operations - fs.ts: OPFS/FileSystem/Memory storage adapter - path.ts: Universal path operations - events.ts: EventEmitter compatibility layer This enables 'write once, run anywhere' for Brainy while maintaining the exact same API. No breaking changes to existing code.
This commit is contained in:
parent
6e8869ecb7
commit
93804be354
31 changed files with 2120 additions and 2028 deletions
40
vite.browser.config.ts
Normal file
40
vite.browser.config.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import { resolve } from 'path'
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
target: 'es2022',
|
||||
lib: {
|
||||
entry: resolve(__dirname, 'dist/browser-build/browserFramework.js'),
|
||||
name: 'Brainy',
|
||||
fileName: 'brainy-browser-bundle',
|
||||
formats: ['es', 'umd']
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
dir: 'dist/browser',
|
||||
entryFileNames: '[name].js',
|
||||
chunkFileNames: '[name].js'
|
||||
}
|
||||
},
|
||||
sourcemap: true,
|
||||
minify: false, // Keep unminified for debugging
|
||||
outDir: 'dist/browser'
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
global: 'globalThis',
|
||||
'process.env': '{}'
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: ['@huggingface/transformers', 'uuid', 'crypto-browserify', 'buffer']
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
crypto: 'crypto-browserify',
|
||||
buffer: 'buffer',
|
||||
process: 'process/browser',
|
||||
util: 'util'
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue