Skip to content

Commit 2a90d3d

Browse files
fix(build): address @ionic/angular bundle size issue
1 parent dfea716 commit 2a90d3d

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

scripts/esbuild/internal-platform-client.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { externalAlias, getBaseEsbuildOptions, getEsbuildAliases, getEsbuildExte
1717
* @param opts build options
1818
* @returns an array of ESBuild option objects
1919
*/
20-
export async function getInternalClientBundle(opts: BuildOptions): Promise<ESBuildOptions[]> {
20+
export async function getInternalClientBundles(opts: BuildOptions): Promise<ESBuildOptions[]> {
2121
const inputClientDir = join(opts.srcDir, 'client');
2222
const outputInternalClientDir = join(opts.output.internalDir, 'client');
2323
const outputInternalClientPolyfillsDir = join(outputInternalClientDir, 'polyfills');
@@ -41,6 +41,10 @@ export async function getInternalClientBundle(opts: BuildOptions): Promise<ESBui
4141

4242
const clientExternal = getEsbuildExternalModules(opts, opts.output.internalDir);
4343

44+
// the runtime imports from `@stencil/core/mock-doc/constants` so we don't
45+
// want to have the existing alias around
46+
delete internalClientAliases['@stencil/core/mock-doc'];
47+
4448
const internalClientBundle: ESBuildOptions = {
4549
...getBaseEsbuildOptions(),
4650
entryPoints: [join(inputClientDir, 'index.ts')],
@@ -59,9 +63,6 @@ export async function getInternalClientBundle(opts: BuildOptions): Promise<ESBui
5963
replace(createReplaceData(opts)),
6064
externalAlias('@app-data', '@stencil/core/internal/app-data'),
6165
externalAlias('@utils/shadow-css', './shadow-css.js'),
62-
// we want to get the esm, not the cjs, since we're creating an esm
63-
// bundle here
64-
externalAlias('@stencil/core/mock-doc', '../../mock-doc/index.js'),
6566
findAndReplaceLoadModule(),
6667
],
6768
};

scripts/esbuild/internal-platform-hydrate.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export async function getInternalPlatformHydrateBundles(opts: BuildOptions): Pro
3535

3636
const hydratePlatformInput = join(hydrateSrcDir, 'platform', 'index.js');
3737

38-
const external = [...getEsbuildExternalModules(opts, outputInternalHydrateDir), '@stencil/core/mock-doc'];
38+
const external = [...getEsbuildExternalModules(opts, outputInternalHydrateDir)];
3939

4040
const internalHydrateAliases = getEsbuildAliases();
4141
internalHydrateAliases['@platform'] = hydratePlatformInput;
42+
delete internalHydrateAliases['@stencil/core/mock-doc'];
4243

4344
const internalHydratePlatformBundle: ESBuildOptions = {
4445
...getBaseEsbuildOptions(),
@@ -54,8 +55,6 @@ export async function getInternalPlatformHydrateBundles(opts: BuildOptions): Pro
5455
plugins: [
5556
externalAlias('@utils/shadow-css', '../client/shadow-css.js'),
5657
externalAlias('@app-data', '@stencil/core/internal/app-data'),
57-
// this needs to be externalized and also pointed at the esm version
58-
externalAlias('@stencil/core/mock-doc', '../../mock-doc/index.js'),
5958
],
6059
};
6160

scripts/esbuild/internal.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { copyStencilInternalDts } from '../bundles/internal';
66
import type { BuildOptions } from '../utils/options';
77
import { writePkgJson } from '../utils/write-pkg-json';
88
import { getInternalAppDataBundles } from './internal-app-data';
9-
import { getInternalClientBundle } from './internal-platform-client';
9+
import { getInternalClientBundles } from './internal-platform-client';
1010
import { getInternalPlatformHydrateBundles } from './internal-platform-hydrate';
1111
import { getInternalTestingBundle } from './internal-platform-testing';
1212
import { getBaseEsbuildOptions, runBuilds } from './util';
@@ -53,13 +53,13 @@ export async function buildInternal(opts: BuildOptions) {
5353
platform: 'node',
5454
};
5555

56-
const clientPlatformBundle = await getInternalClientBundle(opts);
56+
const clientPlatformBundles = await getInternalClientBundles(opts);
5757
const hydratePlatformBundles = await getInternalPlatformHydrateBundles(opts);
5858
const appDataBundles = await getInternalAppDataBundles(opts);
5959
const internalTestingBundle = await getInternalTestingBundle(opts);
6060

6161
return runBuilds(
62-
[shadowCSSBundle, ...clientPlatformBundle, ...hydratePlatformBundles, internalTestingBundle, ...appDataBundles],
62+
[shadowCSSBundle, ...clientPlatformBundles, ...hydratePlatformBundles, internalTestingBundle, ...appDataBundles],
6363
opts,
6464
);
6565
}

src/runtime/dom-extras.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BUILD } from '@app-data';
22
import { getHostRef, plt, supportsShadow } from '@platform';
3-
import { NODE_TYPES } from '@stencil/core/mock-doc';
3+
import { NODE_TYPES } from '@stencil/core/mock-doc/constants';
44
import { CMP_FLAGS, HOST_FLAGS } from '@utils';
55

66
import type * as d from '../declarations';

test.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# first build stencil
4+
npm run build
5+
6+
# then build angular in Ionic Framework
7+
cd ~/Code/ionic-framework/
8+
./build_angular.sh
9+
10+
# then build in the repro
11+
cd ~/Code/scratch-stencil/stencil-4.17-issue/test-test-test/
12+
./install_dev_versions.sh
13+
npm run build

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@stencil/core/internal/client/patch-es": ["src/client/client-patch-esm.ts"],
3737
"@stencil/core/internal/testing": ["src/testing/platform/index.ts"],
3838
"@stencil/core/mock-doc": ["src/mock-doc/index.ts"],
39+
"@stencil/core/mock-doc/*": ["src/mock-doc/*"],
3940
"@stencil/core/testing": ["src/testing/index.ts"],
4041
"@stencil/core/cli": ["src/cli/index.ts"],
4142
"@sys-api-node": ["src/sys/node/index.ts"],

0 commit comments

Comments
 (0)