Skip to content

Commit

Permalink
chore(esbuild): rm inline graceful-fs in dev-server (#5625)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rwaskiewicz authored Apr 10, 2024
1 parent 83cc0b9 commit ab5bc2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 15 additions & 4 deletions scripts/esbuild/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
},
Expand Down
1 change: 0 additions & 1 deletion scripts/esbuild/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function getEsbuildAliases(): Record<string, string> {
// 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',
Expand Down

0 comments on commit ab5bc2b

Please sign in to comment.