forked from material-table-core/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
77 lines (66 loc) · 1.58 KB
/
esbuild.config.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import esbuild from 'esbuild';
import rimraf from 'rimraf';
import path from 'path';
import fs from 'fs';
const { log, error } = console;
/**
* OUTPUT PATH IS SET HERE!!
*
* relative to root of project
*
* !! NO TRAILING SLASH !!
*/
const BUILD_DIR = './dist';
log(`-Cleaning build artifacts from : '${BUILD_DIR}' `);
rimraf(path.resolve(BUILD_DIR), async (err) => {
if (err) {
error(`err cleaning '${BUILD_DIR}' : ${error.stderr}`);
process.exit(1);
}
log('successfully cleaned build artifacts');
const options = {
entryPoints: getFilesRecursive('./src', '.js'),
minifySyntax: true,
minify: true,
bundle: false,
outdir: `${BUILD_DIR}`,
target: 'es6',
// format: 'cjs',
loader: {
'.js': 'jsx'
}
};
log('-Begin building');
try {
await esbuild.build(options);
log(
`\nSuccessfully built to '${BUILD_DIR}''\n[note] : this path is relative to the root of this project)'`
);
} catch (err) {
error(`\nERROR BUILDING : ${err}`);
process.exit(1);
} finally {
process.exit(0);
}
});
/**
* Helper functions
*/
function getFilesRecursive(dirPath, fileExtension = '') {
const paths = traverseDir(dirPath);
if (fileExtension === '') {
return paths;
}
return paths.filter((p) => p.endsWith(fileExtension));
}
function traverseDir(dir, filePaths = []) {
fs.readdirSync(dir).forEach((file) => {
const fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
traverseDir(fullPath, filePaths);
} else {
filePaths.push(fullPath);
}
});
return filePaths;
}