-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.config.ts
64 lines (63 loc) · 1.77 KB
/
build.config.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
import { BuildConfig, BuildContext, defineBuildConfig } from 'unbuild';
import * as current from './package.json';
import { writeFileSync } from 'node:fs';
import path from 'node:path';
const npmPackageFilename = 'package.json';
const npmBuildOptions: BuildConfig = {
declaration: 'compatible',
rollup: {
esbuild: {
minify: false,
},
},
hooks: {
'build:done': (ctx) => {
createNpmPackageJson(ctx);
},
},
};
const productOptions = [
{
name: 'EUID',
packageName: '@unified-id/euid-sdk',
homepage: 'https://euid.eu/',
buildConfig: {
name: 'EUID',
entries: ['./src/euidSdk.ts'],
outDir: 'dist/euid-npm',
...npmBuildOptions,
},
},
{
name: 'UID2',
packageName: '@uid2/uid2-sdk',
homepage: 'https://unifiedid.com/',
buildConfig: {
name: 'UID2',
entries: ['./src/uid2Sdk.ts'],
outDir: 'dist/uid2-npm',
...npmBuildOptions,
},
},
];
function createNpmPackageJson(ctx: BuildContext) {
const options = productOptions.find((p) => p.name === ctx.options.name);
if (!options)
throw new Error(`Could not find product options for build named ${ctx.options.name}`);
const json = {
name: options.packageName,
version: current.version,
description: current.description.replace('UID2', ctx.options.name),
author: current.author,
license: current.license,
engines: current.engines,
repository: current.repository,
scripts: {},
main: ctx.buildEntries.find((e) => e.exports)!.path,
types: ctx.buildEntries.find((e) => e.path.includes('.d.ts'))!.path,
};
writeFileSync(path.join(ctx.options.outDir, npmPackageFilename), JSON.stringify(json), {
flag: 'wx',
});
}
export default defineBuildConfig(productOptions.map((p) => p.buildConfig));