-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
62 lines (54 loc) · 1.3 KB
/
Copy pathbuild.js
File metadata and controls
62 lines (54 loc) · 1.3 KB
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
import { build, context } from 'esbuild';
import progress from '@olton/esbuild-plugin-progress';
import { replace } from 'esbuild-plugin-replace';
import { copyFile, mkdir } from 'node:fs/promises';
import pkg from './package.json' with { type: 'json' };
const production = process.env.MODE === 'production';
const version = pkg.version;
const banner = `
/*!
* Reactive v${version}
* Build: ${new Date().toLocaleString()}
* Copyright ${new Date().getFullYear()} by Serhii Pimenov
* Licensed under MIT
*/
`;
const options = {
entryPoints: ['./src/index.js'],
outfile: './dist/reactive.js',
bundle: true,
sourcemap: false,
format: 'esm',
minify: production,
banner: {
js: banner,
},
plugins: [
progress({
text: 'Building Reactive...',
succeedText: `Reactive built successfully in %s ms!`,
}),
replace({
__BUILD_TIME__: new Date().toLocaleString(),
__VERSION__: version,
}),
],
};
const drop = [];
const copyTypesToDist = async () => {
await mkdir('./dist', { recursive: true });
await copyFile('./types/reactive.d.ts', './dist/reactive.d.ts');
};
if (production) {
await build({
...options,
drop,
});
await copyTypesToDist();
} else {
const ctx = await context({
...options,
});
await copyTypesToDist();
await ctx.watch();
}