forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmodule-build.ts
58 lines (48 loc) · 1.53 KB
/
submodule-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
import { BuildConfig, ensureDir, watcher, target, copyFile, PackageJSON } from './util';
import { join } from 'node:path';
import { BuildOptions, build } from 'esbuild';
import { writePackageJson } from './package-json';
export async function submoduleBuild(config: BuildConfig) {
const submodule = 'build';
const buildSrcDtsDir = join(config.dtsDir, 'packages', 'qwik', 'src', submodule);
const buildDestDir = join(config.distPkgDir, submodule);
ensureDir(buildDestDir);
const opts: BuildOptions = {
entryPoints: [join(config.srcDir, 'build', 'index.ts')],
entryNames: 'index',
outdir: buildDestDir,
bundle: true,
sourcemap: true,
target,
};
const esm = build({
...opts,
format: 'esm',
outExtension: { '.js': '.mjs' },
watch: watcher(config, submodule),
});
const cjs = build({
...opts,
format: 'cjs',
banner: {
js: `globalThis.qwikBuild = (function (module) {`,
},
footer: {
js: `return module.exports; })(typeof module === 'object' && module.exports ? module : { exports: {} });`,
},
outExtension: { '.js': '.cjs' },
watch: watcher(config),
});
await Promise.all([esm, cjs]);
console.log('🐨', submodule);
await copyFile(join(buildSrcDtsDir, 'index.d.ts'), join(buildDestDir, 'index.d.ts'));
const loaderPkg: PackageJSON = {
name: `@builder.io/qwik/build`,
version: config.distVersion,
main: `index.mjs`,
types: `index.d.ts`,
private: true,
type: 'module',
};
await writePackageJson(buildDestDir, loaderPkg);
}