|
@@ -0,0 +1,112 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * Don't touch this file. It will be regenerated by theia build.
|
|
|
|
|
+ * To customize the build process, change ./esbuild.mjs
|
|
|
|
|
+ */
|
|
|
|
|
+import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
|
|
|
|
|
+import { copy } from 'esbuild-plugin-copy';
|
|
|
|
|
+import { compressAssetsPlugin, monacoNlsPlugin, problemMatcherPlugin, sourceMapPathsPlugin } from '@theia/bundle-plugin';
|
|
|
|
|
+import yargs from 'yargs';
|
|
|
|
|
+import { hideBin } from 'yargs/helpers';
|
|
|
|
|
+import resolvePackagePath from 'resolve-package-path';
|
|
|
|
|
+import path from 'node:path';
|
|
|
|
|
+import { fileURLToPath } from 'node:url';
|
|
|
|
|
+
|
|
|
|
|
+export const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
+
|
|
|
|
|
+export function join(...parts) {
|
|
|
|
|
+ return path.join(...parts).replace(/\\/g, '/');
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const { mode, watch, staticCompression } = yargs(hideBin(process.argv)).option('mode', {
|
|
|
|
|
+ description: "Mode to use",
|
|
|
|
|
+ choices: ["development", "production"],
|
|
|
|
|
+ default: "production"
|
|
|
|
|
+}).option('watch', {
|
|
|
|
|
+ description: 'Controls whether to enable watch mode',
|
|
|
|
|
+ type: 'boolean',
|
|
|
|
|
+ default: false
|
|
|
|
|
+}).option('static-compression', {
|
|
|
|
|
+ description: 'Controls whether to emit gzipped copies of the frontend assets. Disabled by default for Electron applications.',
|
|
|
|
|
+ type: 'boolean'
|
|
|
|
|
+}).argv;
|
|
|
|
|
+
|
|
|
|
|
+const production = mode === 'production';
|
|
|
|
|
+const sourcemap = production ? false : 'linked';
|
|
|
|
|
+const minify = production;
|
|
|
|
|
+// Electron loads the frontend from the local backend over loopback, where gzip saves nothing
|
|
|
|
|
+// while the compressed copies still add to the size of the packaged application.
|
|
|
|
|
+const compression = staticCompression ?? false;
|
|
|
|
|
+
|
|
|
|
|
+export { mode, watch, sourcemap, minify, compression };
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @type {Record<string, import('esbuild').Loader>}
|
|
|
|
|
+ */
|
|
|
|
|
+export const loader = {
|
|
|
|
|
+ '.css': 'css',
|
|
|
|
|
+ '.ttf': 'dataurl',
|
|
|
|
|
+ '.eot': 'dataurl',
|
|
|
|
|
+ '.svg': 'dataurl',
|
|
|
|
|
+ '.woff': 'dataurl',
|
|
|
|
|
+ '.woff2': 'dataurl',
|
|
|
|
|
+ '.jpg': 'dataurl',
|
|
|
|
|
+ '.png': 'dataurl',
|
|
|
|
|
+ '.gif': 'dataurl',
|
|
|
|
|
+ '.wasm': 'dataurl',
|
|
|
|
|
+ '.plist': 'dataurl',
|
|
|
|
|
+ '.node': 'file'
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @type {import('esbuild').BuildOptions}
|
|
|
|
|
+ */
|
|
|
|
|
+export const browserOptions = {
|
|
|
|
|
+ entryPoints: {
|
|
|
|
|
+ 'bundle': './src-gen/frontend/index.js',
|
|
|
|
|
+ 'secondary-window': './src-gen/frontend/secondary-index.js',
|
|
|
|
|
+ 'editor.worker': '@theia/monaco-editor-core/esm/vs/editor/common/services/editorWebWorkerMain.js',
|
|
|
|
|
+ 'plugin-worker': '@theia/plugin-ext/lib/hosted/browser/worker/worker-main.js',
|
|
|
|
|
+ },
|
|
|
|
|
+ assetNames: '[name]',
|
|
|
|
|
+ bundle: true,
|
|
|
|
|
+ outdir: 'lib/frontend',
|
|
|
|
|
+ platform: 'browser',
|
|
|
|
|
+ // Support UMD libraries
|
|
|
|
|
+ // but ensure that we also prioritize browser exports where possible
|
|
|
|
|
+ mainFields: ['browser', 'module', 'main'],
|
|
|
|
|
+ loader,
|
|
|
|
|
+ minify,
|
|
|
|
|
+ sourcemap,
|
|
|
|
|
+ plugins: [
|
|
|
|
|
+ problemMatcherPlugin(watch, 'browser'),
|
|
|
|
|
+ monacoNlsPlugin(),
|
|
|
|
|
+ nodeModulesPolyfillPlugin({
|
|
|
|
|
+ globals: {
|
|
|
|
|
+ Buffer: true,
|
|
|
|
|
+ process: false
|
|
|
|
|
+ }
|
|
|
|
|
+ }),
|
|
|
|
|
+ copy({
|
|
|
|
|
+ assets: [
|
|
|
|
|
+ {
|
|
|
|
|
+ // copy secondary window html file to lib folder
|
|
|
|
|
+ from: join(__dirname, 'src-gen/frontend/secondary-window.html'),
|
|
|
|
|
+ to: join(__dirname, 'lib', 'frontend')
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ // copy webview files to lib folder
|
|
|
|
|
+ from: join(resolvePackagePath('@theia/plugin-ext', __dirname), '..', 'src', 'main', 'browser', 'webview', 'pre', '*'),
|
|
|
|
|
+ to: join(__dirname, 'lib', 'webview', 'pre')
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ // copy frontend plugin host files
|
|
|
|
|
+ from: join(resolvePackagePath('@theia/plugin-ext-vscode', __dirname), '..', 'lib', 'node', 'context', 'plugin-vscode-init-fe.js'),
|
|
|
|
|
+ to: join(__dirname, 'lib', 'frontend', 'context')
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ }),
|
|
|
|
|
+ sourceMapPathsPlugin(),
|
|
|
|
|
+ // Keep last: it compresses whatever the preceding plugins emitted.
|
|
|
|
|
+ compressAssetsPlugin({ compress: compression })
|
|
|
|
|
+ ]
|
|
|
|
|
+};
|