-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.js
57 lines (49 loc) · 1.48 KB
/
build.js
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
import esbuild from 'esbuild';
import { default as fsWithCallbacks } from 'fs';
const fs = fsWithCallbacks.promises;
(async () => {
const width = process.stdout.columns || 40;
const hr = '\r\n'.padStart(width / 1.5, '-');
let config = {
entrypoints: ['./web/assets/main.js'],
copy_files: {
'./node_modules/govuk-frontend/dist/govuk/assets': 'web/static/assets',
'./node_modules/@ministryofjustice/frontend/moj/assets': 'web/static/assets',
},
out_dir: './web/static/javascript',
};
console.log(
`${hr}- Building with:\r\n\r\n${config.entrypoints.join('\r\n')}\r\n${hr}`,
);
//files to copy (uses experimental node cp)
console.log(`- Copying files:\r\n`);
for (const [file, file_dest] of Object.entries(config.copy_files)) {
const destination = file_dest;
await fs.cp(file, destination, { recursive: true });
console.log(`Copied file from ${file} file to ${destination}`);
}
let result = await esbuild
.build({
entryPoints: config.entrypoints,
bundle: true,
allowOverwrite: true,
outdir: config.out_dir,
minify: true,
plugins: [],
sourcemap: true,
target: ['es6'],
platform: 'browser',
metafile: true,
supported: {
arrow: false,
},
})
.catch((e) => {
console.log(e);
process.exit(1);
});
console.log(hr);
let text = await esbuild.analyzeMetafile(result.metafile);
console.log(`- Analysis:\r\n${text}${hr}`);
console.log(hr);
})();