-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.js
60 lines (52 loc) · 1.26 KB
/
builder.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
const { serve, build } = require('esbuild');
const fs = require('fs-extra');
const postCssPlugin = require('esbuild-plugin-postcss2');
const tailwindcss = require('tailwindcss');
const autoprefixer = require('autoprefixer');
const isDev = process.env.NODE_ENV !== 'production';
const log = (text) => {
console.log(`\u001b[1;32m${text}\x1b[0m`);
};
/**
* ESBuild Params
* @link https://esbuild.github.io/api/#build-api
*/
const buildParams = {
color: true,
entryPoints: ['src/index.tsx'],
loader: { '.ts': 'tsx', '.fseq': 'binary', '.zip': 'binary' },
plugins: [
postCssPlugin.default({
plugins: [tailwindcss, autoprefixer],
}),
],
outdir: 'dist',
minify: !isDev,
format: 'esm',
target: 'es2020',
bundle: true,
sourcemap: true,
logLevel: 'info',
incremental: true,
treeShaking: true,
metafile: true,
mainFields: ['module', 'main', 'browser'],
};
(async () => {
fs.removeSync('dist');
fs.copySync('public', 'dist');
let serveResult;
try {
await build(buildParams);
serveResult = await serve(
{
servedir: 'dist',
port: 8181,
},
buildParams,
);
log(` ✔︎ Server running on: http://localhost:${serveResult.port}`);
} catch (error) {
console.error(error.message);
}
})();