From 4f955ac78f9d994c041c6cea80ef01468e28a0da Mon Sep 17 00:00:00 2001 From: Alice Pote Date: Tue, 9 Apr 2024 16:24:10 -0400 Subject: [PATCH] chore(build): remove sourcemaps, minified compiler build This removes sourcemaps from the cli, compiler, and dev-server bundles and also removes the unused minified compiler build. All these changes are made to the esbuild-based build. We realized recently that the minified compiler is no longer necessary (it was previously used for in-browser compilation support, and was removed in #4317) and the sourcemaps are similarly not useful, but do take up a significant amount of space. Without this change a packed Stencil tarball is around 12MB, and with this change it drops to 3.5MB. This also adds a check to the Esbuild-based build pipeline where if you run it with the `DEBUG` environment variable it will build sourcemaps for all of the bundles built with Esbuild, so building like ```sh DEBUG=true npm run build ``` will produce a debugging-friendly local build with sourcemaps. STENCIL-1242 --- .gitignore | 1 + scripts/esbuild/cli.ts | 1 - scripts/esbuild/compiler.ts | 13 +------------ scripts/esbuild/dev-server.ts | 1 - scripts/esbuild/util.ts | 13 ++++++++++++- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 86850b86fc2c..9f07f6ce6dd3 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ dist/ /screenshot/index.js.map /screenshot/package.json /screenshot/pixel-match.js +/screenshot/pixel-match.js.map /screenshot/*.d.ts test/**/www/* diff --git a/scripts/esbuild/cli.ts b/scripts/esbuild/cli.ts index 6e8755a406cb..9cb3b8b84695 100644 --- a/scripts/esbuild/cli.ts +++ b/scripts/esbuild/cli.ts @@ -36,7 +36,6 @@ export async function buildCli(opts: BuildOptions) { entryPoints: [join(inputDir, 'index.ts')], external, platform: 'node', - sourcemap: 'linked', } satisfies ESBuildOptions; // ESM build options diff --git a/scripts/esbuild/compiler.ts b/scripts/esbuild/compiler.ts index 9d4c2bc7ef06..1cd5429d7c24 100644 --- a/scripts/esbuild/compiler.ts +++ b/scripts/esbuild/compiler.ts @@ -82,29 +82,18 @@ export async function buildCompiler(opts: BuildOptions) { banner: { js: getBanner(opts, 'Stencil Compiler', true) }, entryPoints: [join(srcDir, 'index.ts')], platform: 'node', - sourcemap: 'linked', external, format: 'cjs', alias, plugins: [replace(replaceData)], - }; - - const compilerBuild = { - ...compilerEsbuildOptions, outfile: join(opts.output.compilerDir, compilerFileName), }; - const minifiedCompilerBuild = { - ...compilerEsbuildOptions, - outfile: join(opts.output.compilerDir, 'stencil.min.js'), - minify: true, - }; - // copy typescript default lib dts files const tsLibNames = await getTypeScriptDefaultLibNames(opts); await Promise.all(tsLibNames.map((f) => fs.copy(join(opts.typescriptLibDir, f), join(opts.output.compilerDir, f)))); - return runBuilds([compilerBuild, minifiedCompilerBuild], opts); + return runBuilds([compilerEsbuildOptions], opts); } /** diff --git a/scripts/esbuild/dev-server.ts b/scripts/esbuild/dev-server.ts index 43e7c4e5344b..afddc4f35492 100644 --- a/scripts/esbuild/dev-server.ts +++ b/scripts/esbuild/dev-server.ts @@ -149,7 +149,6 @@ export async function buildDevServer(opts: BuildOptions) { outfile: join(opts.output.devServerDir, 'client', 'index.js'), format: 'esm', platform: 'node', - sourcemap: false, plugins: [appErrorCssPlugin(opts), replace(createReplaceData(opts))], banner: { js: getBanner(opts, `Stencil Dev Server Client`, true), diff --git a/scripts/esbuild/util.ts b/scripts/esbuild/util.ts index 38baac8262ec..0d2bb3d80c79 100644 --- a/scripts/esbuild/util.ts +++ b/scripts/esbuild/util.ts @@ -109,12 +109,23 @@ export function runBuilds(builds: ESBuildOptions[], opts: BuildOptions): Promise * @returns a base set of options */ export function getBaseEsbuildOptions(): ESBuildOptions { - return { + const options: ESBuildOptions = { bundle: true, legalComments: 'inline', logLevel: 'info', target: getEsbuildTargets(), }; + + // if the `build` subcomment is called with the `DEBUG` env var, like + // + // DEBUG=true npm run build + // + // then we should produce sourcemaps. + if (process.env.DEBUG) { + options.sourcemap = 'linked'; + } + + return options; } /**