|
| 1 | +# Build and Release Guide for @pgflow/client |
| 2 | + |
| 3 | +This document explains how @pgflow/client is built and distributed for different environments. |
| 4 | + |
| 5 | +## Build Outputs |
| 6 | + |
| 7 | +The package is built in multiple formats to support various JavaScript environments: |
| 8 | + |
| 9 | +### Node.js Builds |
| 10 | +- **ES Module** (`dist/index.js`) - Modern JavaScript modules using `import/export` |
| 11 | +- **CommonJS** (`dist/index.cjs`) - Legacy Node.js format using `require()` |
| 12 | +- Both formats exclude dependencies (they are installed automatically via npm) |
| 13 | +- Not minified - allows bundlers to optimize as needed |
| 14 | + |
| 15 | +### Browser Build |
| 16 | +- **IIFE Bundle** (`dist/pgflow-client.browser.js`) - Browser-ready build |
| 17 | +- Includes all dependencies EXCEPT @supabase/supabase-js |
| 18 | +- Expects users to provide their own Supabase client instance |
| 19 | +- Exposes `window.pgflow` global variable with factory functions |
| 20 | +- Always minified with terser for optimal file size (16KB gzipped: 4.3KB) |
| 21 | +- Includes source maps for debugging |
| 22 | + |
| 23 | +### TypeScript Declarations |
| 24 | +- Full type definitions in `dist/src/` directory |
| 25 | +- Main entry point at `dist/index.d.ts` |
| 26 | +- Preserves complete type information for all exports |
| 27 | + |
| 28 | +## Build Configuration |
| 29 | + |
| 30 | +The build uses two Vite configurations: |
| 31 | + |
| 32 | +1. **vite.config.ts** - Library builds (ES and CJS) |
| 33 | + - External dependencies for smaller bundle size |
| 34 | + - Generates TypeScript declarations with vite-plugin-dts |
| 35 | + - No minification - lets consumer's bundler handle it |
| 36 | + |
| 37 | +2. **vite.browser.config.ts** - Browser build |
| 38 | + - Bundles all dependencies |
| 39 | + - IIFE format for direct browser usage |
| 40 | + - Always minified for production use |
| 41 | + |
| 42 | +## Usage in Different Environments |
| 43 | + |
| 44 | +### NPM Package |
| 45 | +```bash |
| 46 | +npm install @pgflow/client |
| 47 | +``` |
| 48 | + |
| 49 | +```javascript |
| 50 | +// ES Modules (recommended) |
| 51 | +import { PgflowClient } from '@pgflow/client'; |
| 52 | + |
| 53 | +// CommonJS |
| 54 | +const { PgflowClient } = require('@pgflow/client'); |
| 55 | +``` |
| 56 | + |
| 57 | +### Browser via CDN |
| 58 | +```html |
| 59 | +<!-- First, load Supabase (required) --> |
| 60 | +<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script> |
| 61 | + |
| 62 | +<!-- Then load pgflow client --> |
| 63 | +<script src="https://unpkg.com/@pgflow/client"></script> |
| 64 | + |
| 65 | +<script> |
| 66 | + // Initialize Supabase (you already have this) |
| 67 | + const supabase = window.supabase.createClient('your-url', 'your-anon-key'); |
| 68 | + |
| 69 | + // Create pgflow client using the factory function |
| 70 | + const pgflow = window.pgflow.createClient(supabase); |
| 71 | +</script> |
| 72 | +``` |
| 73 | + |
| 74 | +### Modern Bundlers |
| 75 | +Bundlers like Webpack, Vite, and Rollup will automatically select the appropriate format: |
| 76 | +- Browsers: Uses the browser build when `browser` condition is set |
| 77 | +- Node.js: Uses ES modules for tree-shaking |
| 78 | +- Fallback: CommonJS for compatibility |
| 79 | + |
| 80 | +## Package.json Configuration |
| 81 | + |
| 82 | +The package.json uses modern packaging standards: |
| 83 | + |
| 84 | +```json |
| 85 | +{ |
| 86 | + "exports": { |
| 87 | + ".": { |
| 88 | + "browser": "./dist/pgflow-client.browser.js", |
| 89 | + "types": "./dist/index.d.ts", |
| 90 | + "import": "./dist/index.js", |
| 91 | + "require": "./dist/index.cjs", |
| 92 | + "default": "./dist/index.js" |
| 93 | + } |
| 94 | + }, |
| 95 | + "unpkg": "./dist/pgflow-client.browser.js", |
| 96 | + "files": ["dist/**/*", "README.md", "LICENSE", "CHANGELOG.md"] |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +- **exports**: Conditional exports for different environments |
| 101 | +- **unpkg**: CDN entry point for browsers |
| 102 | +- **files**: Only necessary files included in npm package |
| 103 | + |
| 104 | +## Building Locally |
| 105 | + |
| 106 | +```bash |
| 107 | +# Build all formats |
| 108 | +pnpm nx build client |
| 109 | + |
| 110 | +# Build only library formats |
| 111 | +pnpm nx build:lib client |
| 112 | + |
| 113 | +# Build only browser format |
| 114 | +pnpm nx build:browser client |
| 115 | +``` |
| 116 | + |
| 117 | +## Dependencies |
| 118 | + |
| 119 | +- **Runtime**: @pgflow/core, @pgflow/dsl, @supabase/supabase-js, nanoevents, uuid |
| 120 | + |
| 121 | +All runtime dependencies are automatically installed when you install @pgflow/client. The browser build includes all these dependencies bundled together. |
0 commit comments