| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**
- * 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. Enabled by default in production mode.',
- type: 'boolean'
- }).argv;
- const production = mode === 'production';
- const sourcemap = production ? false : 'linked';
- const minify = production;
- // Compressing on every rebuild would slow down watch mode, so this only pays off for production builds.
- const compression = staticCompression ?? production;
- 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 })
- ]
- };
|