-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathesbuild.static.mjs
More file actions
96 lines (84 loc) · 2.77 KB
/
esbuild.static.mjs
File metadata and controls
96 lines (84 loc) · 2.77 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/// <reference types="node" />
/* eslint-env node */
/* eslint-disable no-console */
/* eslint-disable no-magic-numbers */
/* eslint-disable no-restricted-globals */
import { injectCSSPlugin } from '@msinternal/botframework-webchat-styles/build';
import { build, context } from 'esbuild';
import { mkdir, writeFile } from 'fs/promises';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { cssPlugin } from '../../esbuildPlugins.mjs';
// TODO: [P0] We cannot import TypeScript file here.
const fluentStyleContentPlaceholder = '@--FLUENT-STYLES-CONTENT--@';
function createWatcherPlugin(name) {
/** @type { import('esbuild').Plugin } */
return {
name: 'watcher',
setup(build) {
let buildStart = Date.now();
console.log([name, `Running in watch mode`].filter(Boolean).join(' '));
build.onStart(() => {
buildStart = Date.now();
console.log([name, `Build start`].filter(Boolean).join(' '));
});
build.onEnd(() =>
console.log([name, `⚡ Build success in ${Date.now() - buildStart}ms`].filter(Boolean).join(' '))
);
}
};
}
/** @type { import('esbuild').BuildOptions } */
const config = {
alias: {
'html-react-parser': '@msinternal/html-react-parser'
},
bundle: true,
chunkNames: `botframework-webchat-fluent-theme.[name]-[hash]`,
entryNames: `[name]`,
entryPoints: {
'botframework-webchat-fluent-theme': './src/index.ts'
},
external: ['botframework-webchat*', 'react', 'react-dom'],
format: 'esm',
loader: { '.js': 'jsx' },
minify: true,
metafile: true,
outdir: resolve(fileURLToPath(import.meta.url), `../static/`),
platform: 'browser',
plugins: [
cssPlugin,
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder }),
{
// `write` is set to `false`, we need to emit files ourselves.
name: 'emit-output',
setup(build) {
build.onEnd(async args => {
await Promise.all(
args.outputFiles.map(async entry => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
await mkdir(dirname(entry.path), { recursive: true });
// eslint-disable-next-line security/detect-non-literal-fs-filename
await writeFile(entry.path, entry.contents);
})
);
});
}
}
],
sourcemap: true,
splitting: true,
target: ['chrome100', 'firefox100', 'safari15'],
// Set write to false for the `injectCSSPlugin` to work.
// We will emit the output in another plugin.
write: false
};
(async () => {
const [_0, _1, watch] = process.argv;
if (watch === '--watch') {
config.plugins.push(createWatcherPlugin());
await (await context(config)).watch({ delay: 200 });
} else {
await build(config);
}
})();