-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathesbuild.views.mjs
More file actions
76 lines (65 loc) · 2.08 KB
/
esbuild.views.mjs
File metadata and controls
76 lines (65 loc) · 2.08 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isAutoDebug, isAutoWatch } from '@microsoft/vscode-azext-eng/esbuild';
import esbuild from 'esbuild';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const outdir = path.resolve(__dirname, 'dist');
const commonConfig = {
entryPoints: {
views: path.resolve(__dirname, 'src/webviews/index.tsx'),
},
bundle: true,
outdir: outdir,
format: 'esm',
platform: 'browser', //todo: remove (platform is auto browser if not specified)
target: 'es2022',
sourcemap: isAutoWatch,
minify: !isAutoWatch,
metafile: isAutoDebug,
splitting: false,
inject: [path.resolve(__dirname, 'react-shim.js')],
loader: {
'.ts': 'ts',
'.tsx': 'tsx',
'.css': 'css',
'.scss': 'css',
'.ttf': 'dataurl',
'.woff': 'dataurl',
'.woff2': 'dataurl',
},
plugins: [
{
name: 'sass',
setup(build) {
build.onLoad({ filter: /\.s[ac]ss$/ }, async (args) => {
const sass = await import('sass');
const result = sass.compile(args.path);
return {
contents: result.css,
loader: 'css',
};
});
},
},
],
logLevel: 'info'
};
const ctx = await esbuild.context({
...commonConfig,
outdir,
});
// Always do an initial rebuild to ensure views.js exists
await ctx.rebuild();
if (isAutoWatch) {
await ctx.watch();
console.log('Watching webview bundle...');
await new Promise(() => { });
} else {
await ctx.rebuild();
await ctx.dispose();
}