comparison esbuild.config.mjs @ 48:bdaa6e2c18d6

Update build script to newest esbuild APIs.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 02 Oct 2023 09:50:53 -0700
parents d52beb77d109
children
comparison
equal deleted inserted replaced
47:8e8019698f16 48:bdaa6e2c18d6
3 import builtins from 'builtin-modules' 3 import builtins from 'builtin-modules'
4 4
5 const banner = 5 const banner =
6 `/* 6 `/*
7 THIS IS A GENERATED/BUNDLED FILE BY ESBUILD 7 THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
8 if you want to view the source, please visit one of the following: 8
9 https://hg.bolt80.com/obsidian-remember-file-state 9 If you want to view the source, please visit one of the following:
10 https://hg.sr.ht/~ludovicchabant/obsidian-remember-file-state 10 - https://hg.bolt80.com/obsidian-remember-file-state
11 https://github.com/ludovicchabant/obsidian-remember-file-state 11 - https://hg.sr.ht/~ludovicchabant/obsidian-remember-file-state
12 - https://github.com/ludovicchabant/obsidian-remember-file-state
12 */ 13 */
13 `; 14 `;
14 15
15 const prod = (process.argv[2] === 'production'); 16 const prod = (process.argv[2] === 'production');
16 const dogfood = (process.argv[2] === 'dogfood'); 17 const dogfood = (process.argv[2] === 'dogfood');
24 throw("Please provide an output directory to put the dog food into"); 25 throw("Please provide an output directory to put the dog food into");
25 } 26 }
26 27
27 const outfile = outdir + 'main.js'; 28 const outfile = outdir + 'main.js';
28 29
29 esbuild.build({ 30 const context = await esbuild.context({
30 banner: { 31 banner: {
31 js: banner, 32 js: banner,
32 }, 33 },
33 entryPoints: ['src/main.ts'], 34 entryPoints: ['src/main.ts'],
34 bundle: true, 35 bundle: true,
56 '@codemirror/text', 57 '@codemirror/text',
57 '@codemirror/tooltip', 58 '@codemirror/tooltip',
58 '@codemirror/view', 59 '@codemirror/view',
59 ...builtins], 60 ...builtins],
60 format: 'cjs', 61 format: 'cjs',
61 watch: !prod, 62 target: 'es2018',
62 target: 'es2016',
63 logLevel: "info", 63 logLevel: "info",
64 sourcemap: prod ? false : 'inline', 64 sourcemap: prod ? false : 'inline',
65 treeShaking: true, 65 treeShaking: true,
66 outfile: outfile, 66 outfile: outfile,
67 }).catch(() => process.exit(1)); 67 });
68
69 if (prod) {
70 await context.rebuild();
71 process.exit(0);
72 } else {
73 await context.watch();
74 }
75