- package.json with Preact 10 + Vite 6 + TypeScript 5 - vite.config: IIFE + ESM lib outputs, preact/compat alias, CSS inlined via ?inline import (no separate .css file emitted - single-file IIFE) - tsconfig.json (src/) + tsconfig.node.json (vite.config.ts) - src/index.ts: entry, injects <style>, mounts <Widget /> on script load - src/config.ts: parses data-bot-id + data-api-key + data-server-url - src/vite-env.d.ts: ?inline CSS type declaration - src/storage/visitor.ts: localStorage UUID v4 with in-memory fallback - src/transport/ws-client.ts: WebSocket primary, exponential reconnect (max 5 retries ~30s cap), HTTP polling fallback at /webchat/history every 5s - src/ui/widget.tsx: root Preact component, transport lifecycle, send handler - src/ui/bubble.tsx: floating FAB with chat/close SVG icons, position aware - src/ui/panel.tsx: header + scrollable message list + typing indicator + input - src/ui/message.tsx: single message bubble (user right/bot left), timestamp - src/ui/theme.css: CSS variables (--messenzy-primary/accent overridable) - Build output: dist/messenzy-widget.iife.js 25.3 kB (9.7 kB gz), zero errors - typecheck: clean (strict + exactOptionalPropertyTypes) - .gitignore: node_modules/ dist/ .vite/ .env* .DS_Store - README: integration snippet, script attributes table, theme, build instructions
32 lines
739 B
TypeScript
32 lines
739 B
TypeScript
import { defineConfig } from 'vite';
|
|
import { resolve } from 'path';
|
|
|
|
export default defineConfig({
|
|
resolve: {
|
|
alias: {
|
|
react: 'preact/compat',
|
|
'react-dom': 'preact/compat',
|
|
'react-dom/test-utils': 'preact/test-utils',
|
|
'react/jsx-runtime': 'preact/jsx-runtime',
|
|
},
|
|
},
|
|
build: {
|
|
lib: {
|
|
entry: resolve(__dirname, 'src/index.ts'),
|
|
name: 'MeszenzyWidget',
|
|
formats: ['iife', 'es'],
|
|
fileName: (format) =>
|
|
format === 'iife' ? 'messenzy-widget.iife.js' : 'messenzy-widget.js',
|
|
},
|
|
rollupOptions: {
|
|
output: {
|
|
inlineDynamicImports: true,
|
|
},
|
|
},
|
|
cssCodeSplit: false,
|
|
minify: 'esbuild',
|
|
sourcemap: false,
|
|
target: 'es2022',
|
|
},
|
|
});
|