Skip to content

Commit

Permalink
chore(build): remove sourcemaps, minified compiler build
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alicewriteswrongs committed Apr 9, 2024
1 parent b3886aa commit 4f955ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
1 change: 0 additions & 1 deletion scripts/esbuild/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions scripts/esbuild/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
1 change: 0 additions & 1 deletion scripts/esbuild/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 12 additions & 1 deletion scripts/esbuild/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 4f955ac

Please sign in to comment.