-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathesbuild.js
127 lines (121 loc) · 3.24 KB
/
esbuild.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const esbuild = require('esbuild');
const { resolve } = require('path');
const tailwindcss = require('tailwindcss');
const autoprefixer = require('autoprefixer');
const stylePlugin = require('esbuild-style-plugin');
const svgr = require('esbuild-plugin-svgr');
const babelFlowPlugin = require('./esbuild/flow-plugin');
const { esbuildProblemMatcherPlugin, copyFilesPlugin } = require('./src/esbuild-plugins');
const { copyDirectory } = require('./src/utils/files');
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
async function extension() {
await copyDirectory('src/devtools/react/dist', './dist', {
ignore: ['standalone.*'],
});
const ctx = await esbuild.context({
entryPoints: ['src/extension.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
external: ['vscode', 'bufferutil', 'utf-8-validate'],
outfile: 'dist/extension.js',
// logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
return await ctx.watch();
} else {
await ctx.rebuild();
return await ctx.dispose();
}
}
async function webview() {
const ctx = await esbuild.context({
entryPoints: ['src/webviews/index.tsx', 'src/webviews/style.css'],
bundle: true,
format: 'esm',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'browser',
outdir: 'dist',
jsx: 'automatic',
define: {
'process.env.NODE_ENV': production ? '"production"' : '"development"',
'process.env.IS_PRODUCTION': production ? 'true' : 'false',
},
// logLevel: 'silent',
plugins: [
stylePlugin({
postcss: {
plugins: [tailwindcss, autoprefixer],
},
}),
svgr(),
copyFilesPlugin([{ from: './src/icon.png', to: 'icon.png' }]),
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
loader: {
'.svg': 'file',
'.ttf': 'file',
},
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}
async function preview() {
const ctx = await esbuild.context({
entryPoints: ['src/preview-src/preview-index.ts', 'src/preview-src/preview-main.css'],
bundle: true,
format: 'esm',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'browser',
outdir: 'dist',
// external: ['./sw.js'],
jsx: 'automatic',
define: {
'process.env.NODE_ENV': production ? '"production"' : '"development"',
'process.env.IS_PRODUCTION': production ? 'true' : 'false',
},
// logLevel: 'silent',
plugins: [
// copyFilesPlugin([{ from: './src/preview-src/icon.png', to: 'preview-icon.png' }]),
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
loader: {
'.svg': 'file',
'.ttf': 'file',
},
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}
(async () => {
try {
extension();
preview();
webview();
} catch (error) {
console.error(error);
process.exit(1);
}
})();