From ab5bc2bd25b267f100ba6cb3482c9d44c6c703b4 Mon Sep 17 00:00:00 2001 From: Ryan Waskiewicz Date: Wed, 10 Apr 2024 12:28:02 -0400 Subject: [PATCH] chore(esbuild): rm inline graceful-fs in dev-server (#5625) * chore(esbuild): rm inline graceful-fs in dev-server update the building of the dev-server such that we no longer inline graceful-fs in the dev-server. this saves us approximately 10kb in total - 20kb get removed from dev-server/server-process.js, and 10kb are added to `sys/node/index.ts`. this is accomplished by removing graceful-fs from the shared alias list, as it's only needed in `sys` and `dev-server`. we them mark the library as "external" so that esbuild resolves to the version held on to by the `sys` submodule STENCIL-1243 * review(ap): externalize graceful-fs --- scripts/esbuild/dev-server.ts | 19 +++++++++++++++---- scripts/esbuild/util.ts | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/esbuild/dev-server.ts b/scripts/esbuild/dev-server.ts index afddc4f3549..4fc4ab34fa4 100644 --- a/scripts/esbuild/dev-server.ts +++ b/scripts/esbuild/dev-server.ts @@ -11,7 +11,7 @@ import { bundleExternal, sysNodeBundleCacheDir } from '../bundles/sys-node'; import { getBanner } from '../utils/banner'; import { type BuildOptions, createReplaceData } from '../utils/options'; import { writePkgJson } from '../utils/write-pkg-json'; -import { getBaseEsbuildOptions, getEsbuildAliases, getFirstOutputFile, runBuilds } from './util'; +import { externalAlias, getBaseEsbuildOptions, getEsbuildAliases, getFirstOutputFile, runBuilds } from './util'; const CONNECTOR_NAME = 'connector.html'; @@ -70,9 +70,15 @@ export async function buildDevServer(opts: BuildOptions) { bundleExternal(opts, opts.output.devServerDir, cachedDir, 'open-in-editor-api.js'), ]); - const devServerAliases = getEsbuildAliases(); - const external = [...builtinModules, './ws.js', './open-in-editor-api']; + const external = [ + ...builtinModules, + // ws.js is externally bundled + './ws.js', + // open-in-editor-api is externally bundled + './open-in-editor-api', + ]; + const devServerAliases = getEsbuildAliases(); const devServerIndexEsbuildOptions = { ...getBaseEsbuildOptions(), alias: devServerAliases, @@ -100,7 +106,12 @@ export async function buildDevServer(opts: BuildOptions) { format: 'cjs', platform: 'node', write: false, - plugins: [esm2CJSPlugin(), contentTypesPlugin(opts), replace(createReplaceData(opts))], + plugins: [ + esm2CJSPlugin(), + contentTypesPlugin(opts), + replace(createReplaceData(opts)), + externalAlias('graceful-fs', '../sys/node/graceful-fs.js'), + ], banner: { js: getBanner(opts, `Stencil Dev Server Process`, true), }, diff --git a/scripts/esbuild/util.ts b/scripts/esbuild/util.ts index 46b33fd5732..844eaf87c43 100644 --- a/scripts/esbuild/util.ts +++ b/scripts/esbuild/util.ts @@ -30,7 +30,6 @@ export function getEsbuildAliases(): Record { // reference the same file prompts: './sys/node/prompts.js', glob: './sys/node/glob.js', - 'graceful-fs': './sys/node/graceful-fs.js', // dev server related aliases ws: './ws.js',