Skip to content

Commit

Permalink
fix(dist-custom-elements): stop duplicate @stencil/core (#6109)
Browse files Browse the repository at this point in the history
* i mean ... it doesn't seam to break anything?

* chore: only do include whole core for non lazy

* chore: test for build conditionals

---------

Co-authored-by: John Jenkins <[email protected]>
  • Loading branch information
johnjenkins and John Jenkins authored Jan 24, 2025
1 parent 66340b2 commit dc4c88f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/compiler/bundle/bundle-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,21 @@ export const getRollupOptions = (

const beforePlugins = config.rollupPlugins.before || [];
const afterPlugins = config.rollupPlugins.after || [];

const rollupOptions: RollupOptions = {
input: bundleOpts.inputs,
output: {
inlineDynamicImports: bundleOpts.inlineDynamicImports ?? false,
},

plugins: [
coreResolvePlugin(config, compilerCtx, bundleOpts.platform, !!bundleOpts.externalRuntime),
coreResolvePlugin(
config,
compilerCtx,
bundleOpts.platform,
!!bundleOpts.externalRuntime,
bundleOpts.conditionals?.lazyLoad ?? false,
),
appDataPlugin(config, compilerCtx, buildCtx, bundleOpts.conditionals, bundleOpts.platform),
lazyComponentPlugin(buildCtx),
loaderPlugin(bundleOpts.loader),
Expand Down
12 changes: 9 additions & 3 deletions src/compiler/bundle/core-resolve-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const coreResolvePlugin = (
compilerCtx: d.CompilerCtx,
platform: 'client' | 'hydrate' | 'worker',
externalRuntime: boolean,
lazyLoad: boolean,
): Plugin => {
const compilerExe = config.sys.getCompilerExecutingPath();
const internalClient = getStencilInternalModule(config, compilerExe, 'client/index.js');
Expand All @@ -38,9 +39,14 @@ export const coreResolvePlugin = (
external: true,
};
}
// adding ?app-data=conditional as an identifier to ensure we don't
// use the default app-data, but build a custom one based on component meta
return internalClient + APP_DATA_CONDITIONAL;
if (lazyLoad) {
// with a lazy / dist build, add `?app-data=conditional` as an identifier to ensure we don't
// use the default app-data, but build a custom one based on component meta
return internalClient + APP_DATA_CONDITIONAL;
}
// for a non-lazy / dist-custom-elements build, use the default, complete core.
// This ensures all features are available for any importer library
return internalClient;
}
if (platform === 'hydrate') {
return internalHydrate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export * from '${USER_INDEX_ENTRY_ID}';
describe('bundleCustomElements', () => {
it('should set a diagnostic if no `dir` prop on the output target', async () => {
const { config, compilerCtx, buildCtx } = setup();
const outputTarget: OutputTargetDistCustomElements = { type: DIST_CUSTOM_ELEMENTS };
const outputTarget: OutputTargetDistCustomElements = { type: DIST_CUSTOM_ELEMENTS, externalRuntime: true };
await bundleCustomElements(config, compilerCtx, buildCtx, outputTarget);
expect(buildCtx.diagnostics).toEqual([
{
Expand Down

0 comments on commit dc4c88f

Please sign in to comment.