-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.js
65 lines (61 loc) · 1.82 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import esbuild from 'esbuild';
import { polyfillNode } from 'esbuild-plugin-polyfill-node';
import { sentryEsbuildPlugin } from '@sentry/esbuild-plugin';
import dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const distPath = path.join(__dirname, 'dist');
// Clean dist directory
fs.rm(distPath, { recursive: true }, (err) => {
if (err) throw err;
fs.mkdir(distPath, (err) => {
if (err) throw err;
});
});
dotenv.config({ path: path.join(__dirname, '.env') });
esbuild.build({
entryPoints: ['src/worker.js'],
bundle: true,
outfile: 'dist/worker.js',
format: 'esm',
platform: 'browser', // Changed from 'node' to 'browser'
allowOverwrite: true,
target: 'ES2020',
plugins: [
polyfillNode({
polyfills: {
fs: true,
path: true,
buffer: true,
// Explicitly disable worker_threads polyfill
worker_threads: false,
crypto: true,
},
}),
sentryEsbuildPlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
include: './dist',
authToken: process.env.SENTRY_AUTH_TOKEN,
}),
],
define: {
'process.env.NODE_ENV': '"production"',
'global': 'globalThis',
},
external: [
'@langchain/core/documents',
'@langchain/core/utils/tiktoken',
'@langchain/textsplitters',
'fastembed',
'@fal-ai/client',
'unique-names-generator',
'tough-cookie',
'set-cookie-parser',
'cloudflare:workers',
// Add node-specific modules to external
'worker_threads',
'node-domexception'
]
}).catch(() => process.exit(1));