-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
99 lines (99 loc) · 2.43 KB
/
build.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { preprocess } from '@ctx-core/preprocess'
import { rebuild_tailwind_plugin_ } from '@rebuildjs/tailwindcss'
import cssnano from 'cssnano'
import { import_meta_env_ } from 'ctx-core/env'
import { is_entry_file_ } from 'ctx-core/fs'
import { type Plugin } from 'esbuild'
import esmfile_ from 'esbuild-plugin-esmfile'
import { esmcss_esbuild_plugin_ } from 'esmcss'
import { readdir } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import {
type relysjs__build_config_T,
relysjs__ready__wait,
relysjs_browser__build,
relysjs_server__build
} from 'relysjs/server'
import { config__init } from './config.js'
import tailwindcss_config from './tailwind.config.js'
export async function build(config?:relysjs__build_config_T) {
config__init()
const rebuild_tailwind_plugin = rebuild_tailwind_plugin_({
tailwindcss_config,
postcss_plugin_a1_: tailwindcss_plugin=>[
tailwindcss_plugin as never,
cssnano({ preset: 'default' })
],
})
const preprocess_plugin = preprocess_plugin_()
const esmfile = esmfile_()
await Promise.all([
relysjs_browser__build({
...config ?? {},
publicPath: '/',
plugins: [
rebuild_tailwind_plugin,
preprocess_plugin,
esmfile,
],
}),
relysjs_server__build({
...config ?? {},
target: 'es2022',
external: await server_external_(),
minify: false,
publicPath: '/',
plugins: [
esmcss_esbuild_plugin_(),
rebuild_tailwind_plugin,
preprocess_plugin,
esmfile,
],
}),
relysjs__ready__wait(10_000),
])
}
function server_external_() {
return readdir(
join(
dirname(new URL(import.meta.url).pathname),
'..',
'..',
'node_modules'),
).then(file_a1=>[
...file_a1
.filter(file=>file !== '@btakita' && file !== '@rappstack')
.map(file=>file[0] === '@' ? file + '/*' : file),
'bun',
'bun:*'
])
}
if (is_entry_file_(import.meta.url, process.argv[1])) {
build({
rebuildjs: { watch: false },
relysjs: { app__start: false }
}).then(()=>process.exit(0))
.catch(err=>{
console.error(err)
process.exit(1)
})
}
function preprocess_plugin_():Plugin {
return {
name: 'preprocess',
setup(build) {
if (import_meta_env_().NODE_ENV !== 'production') {
build.onLoad({ filter: /(\/ctx-core\/?.*|\/hyop\/?.*)$/ }, async ({ path })=>{
const source = await Bun.file(path).text()
return {
contents: preprocess(
source,
{ DEBUG: '1' },
{ type: 'js' }),
loader: 'ts'
}
})
}
}
}
}