-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathesbuild.config.js
More file actions
63 lines (55 loc) · 1.51 KB
/
esbuild.config.js
File metadata and controls
63 lines (55 loc) · 1.51 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
63
import esbuild from 'esbuild';
import fse from 'fs-extra';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isDev = process.argv.includes('--dev');
const assetLoader = ['.ttf', '.svg', '.eot', '.woff', '.woff2'].reduce((acc, ext) => {
acc[ext] = 'file';
return acc;
}, {});
const jsOptions = {
entryPoints: ['./src/index.ts'],
bundle: true,
outdir: 'dist/js',
format: 'esm',
minify: true,
sourcemap: isDev,
loader: { '.ts': 'ts', '.tsx': 'tsx', ...assetLoader },
logLevel: isDev ? 'info' : 'error',
};
const cssOptions = {
entryPoints: ["./src/style.css"],
bundle: true,
minify: true,
sourcemap: isDev,
outdir: path.resolve(__dirname, 'dist/css'),
entryNames: 'style',
}
const copyAssets = async () => {
fse.ensureDirSync(path.resolve(__dirname, 'dist/js'));
await fse.copy(
'node_modules/monaco-editor/esm/vs',
'dist/js/monaco-editor/vs'
)
};
const build = async (options, watch = false) => {
const ctx = await esbuild.context(options);
if (watch) {
await ctx.watch();
console.log(`Watching ${options.outdir}...`);
} else {
await ctx.rebuild();
await ctx.dispose();
console.log(`Built ${options.outdir}`);
}
};
(async () => {
await Promise.all([
build(jsOptions, isDev),
build(cssOptions, isDev),
copyAssets()
]);
})();