mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:31:48 +00:00
Use [esbuild](https://esbuild.github.io/) instead of Webpack for builds of `client/web`, for faster builds (dev and prod) and greater dev-prod parity. This PR completely removes all use of Webpack in this repository. `client/web` is the last build target that still uses Webpack; all others have been recently migrated to esbuild. Most devs here have been using esbuild for local dev of `client/web` for the last 6-12 months anyway. The change here is that now our production builds will be built by esbuild. All sg commands, integration/e2e tests, etc., continue to work as-is. The bundlesize report will take a while to stabilize because the new build products use different filenames. ## Benchmarks Running `pnpm run generate && time pnpm -C client/web run task:gulp webBuild` and taking the `time` output from the last command: - Webpack: 62.5s - esbuild: 6.7s Note: This understates esbuild's victory for 2 reasons: (1) because esbuild is building both the main and embed entrypoints, whereas Webpack only builds the main entrypoint in this benchmark) and (2) because a lot of it is in the fixed startup time of `gulp`; esbuild incremental rebuilds during local dev only take ~1s. ## Notes We no longer use Babel to produce web builds (we use esbuild), so we don't need any Babel plugins that optimize the output or improve browser compatibility. Right now, Babel is only used by Jest (for tests) and by Bazel as an intermediate step.
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import { existsSync } from 'fs'
|
|
import path from 'path'
|
|
|
|
import * as esbuild from 'esbuild'
|
|
import { rm } from 'shelljs'
|
|
|
|
import {
|
|
packageResolutionPlugin,
|
|
stylePlugin,
|
|
workerPlugin,
|
|
buildTimerPlugin,
|
|
} from '@sourcegraph/build-config/src/esbuild/plugins'
|
|
|
|
const rootPath = path.resolve(__dirname, '../../../')
|
|
const jetbrainsWorkspacePath = path.resolve(rootPath, 'client', 'jetbrains')
|
|
const webviewSourcePath = path.resolve(jetbrainsWorkspacePath, 'webview', 'src')
|
|
|
|
// Build artifacts are put directly into the JetBrains resources folder
|
|
const distributionPath = path.resolve(jetbrainsWorkspacePath, 'src', 'main', 'resources', 'dist')
|
|
|
|
export async function build(): Promise<void> {
|
|
if (existsSync(distributionPath)) {
|
|
rm('-rf', distributionPath)
|
|
}
|
|
|
|
const ctx = await esbuild.context({
|
|
entryPoints: {
|
|
search: path.resolve(webviewSourcePath, 'search', 'index.tsx'),
|
|
bridgeMock: path.resolve(webviewSourcePath, 'bridge-mock', 'index.ts'),
|
|
style: path.join(webviewSourcePath, 'index.scss'),
|
|
},
|
|
bundle: true,
|
|
format: 'esm',
|
|
platform: 'browser',
|
|
define: {
|
|
'process.env.IS_TEST': 'false',
|
|
global: 'globalThis',
|
|
},
|
|
splitting: true,
|
|
inject: ['./scripts/react-shim.js', './scripts/process-shim.js', './scripts/buffer-shim.js'],
|
|
plugins: [
|
|
stylePlugin,
|
|
workerPlugin,
|
|
packageResolutionPlugin({
|
|
process: require.resolve('process/browser'),
|
|
path: require.resolve('path-browserify'),
|
|
http: require.resolve('stream-http'),
|
|
https: require.resolve('https-browserify'),
|
|
url: require.resolve('url'),
|
|
util: require.resolve('util'),
|
|
}),
|
|
buildTimerPlugin,
|
|
],
|
|
loader: {
|
|
'.ttf': 'file',
|
|
},
|
|
assetNames: '[name]',
|
|
minify: true,
|
|
sourcemap: true,
|
|
outdir: distributionPath,
|
|
})
|
|
|
|
if (process.env.WATCH) {
|
|
await ctx.watch()
|
|
} else {
|
|
await ctx.rebuild()
|
|
await ctx.dispose()
|
|
}
|
|
}
|