-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild-x.config.js
62 lines (57 loc) · 1.39 KB
/
esbuild-x.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
/* global module, require */
const open = require('open');
const esbuildX = require('esbuild-x');
const rimraf = require('rimraf').sync;
const { minifyHtmlPlugin, minifyCssPlugin } = esbuildX.plugins;
const { copy, injectEsbuildResult, runStaticServer, watchAndReload } = esbuildX.postBuilds;
const config = {};
/**
* write github pages to docs folder
*/
config.build = {
entryPoints: ['./src/main.js'],
outdir: 'docs',
plugins: [minifyCssPlugin, minifyHtmlPlugin],
preBuilds: [ function clear() {rimraf('docs')} ],
postBuilds: [
copy('src/**/!(*.js) docs'),
injectEsbuildResult(),
]
};
/**
* run src directory as a static server
*/
config.serve = {
entryPoints: ['src/main.js'],
loader: { '.html': 'text', '.css': 'text' },
write: false,
postBuilds: [
copy('src/**/!(*.js) dist'),
injectEsbuildResult(),
runStaticServer('dist'),
watchAndReload(['src', 'lib']),
_ => open('http://localhost:9100/')
]
};
/**
* write npm module to dist directory
*/
config.lib = {
entryPoints: ['lib/index.js'],
entryNames: '[name]',
outdir: 'dist',
bundle: true,
metafile: true,
write: true,
minify: false,
format: 'esm',
target: ['es2019'],
sourcemap: false,
postBuilds: [
async function(_, result) {
let text = await esbuildX.analyzeMetafile(result.metafile, {verbose: true});
console.log(text);
}
]
};
module.exports = config;