Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

assets.ts

55 lines1.5 KB

1import { createAssetServer } from 'remix/assets'
2import { uiHmr } from 'remix/ui-hmr/assets'
3​
4const rootDir = process.cwd()
5const nodeEnv = process.env.NODE_ENV ?? 'development'
6const isDevelopment = nodeEnv === 'development'
7const isHmr = Boolean(isDevelopment && process.env.REMIX_NODE_HMR)
8​
9export const assets = createAssetServer({
10 basePath: '/assets',
11 rootDir,
12 // pnpm stores workspace packages under the repo root. Mount that store so
13 // `remix/ui` and `@tanstack/*` resolve inside a configured mount.
14 mounts: {
15 app: 'app',
16 npm: 'node_modules',
17 workspace: '../../node_modules',
18 packages: '../../packages',
19 },
20​
21 allowFiles: [
22 'app/routes.ts',
23 'app/**/public/**',
24 'app/ui/**',
25 'app/lib/**',
26 'app/data/**',
27 'app/shims/**',
28 ],
29 allowPackages: [
30 'remix',
31 '@tanstack/ai-remix',
32 '@tanstack/ai-client',
33 '@tanstack/ai',
34 'zod',
35 ],
36 denyFiles: ['app/**/*.test.*'],
37 sourceMaps: isDevelopment ? 'external' : undefined,
38 minify: !isDevelopment,
39 watch: isDevelopment,
40 hmr: isHmr
41 ? async () =>
42 (await import('remix/node-hmr/runtime')).createBrowserHmrChannel()
43 : undefined,
44 scripts: {
45 // Remix's unbundled asset server cannot compile this CJS package.
46 external: ['partial-json'],
47 loaders: isHmr ? [uiHmr()] : undefined,
48 },
49})
50​
51const entry = 'app/actions/public/entry.ts'
52​
53export const entryHref = await assets.getHref(entry)
54export const entryPreloads = await assets.getPreloads(entry)
55export const partialJsonHref = await assets.getHref('app/shims/partial-json.ts')