From 2c6884970baf9f01f36d0843ce4ad59745e5a1f0 Mon Sep 17 00:00:00 2001 From: Andrew Kimpton Date: Mon, 24 Jun 2024 20:59:25 +0100 Subject: [PATCH] fix(compiler): support rollup's external input option (#3227) Pluck the external option from the stencil config and pass it through to rollup. Co-authored-by: Christian Bromann --- src/compiler/bundle/bundle-output.ts | 2 ++ src/compiler/config/test/validate-rollup-config.spec.ts | 2 ++ src/compiler/config/validate-rollup-config.ts | 2 +- src/declarations/stencil-public-compiler.ts | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/bundle/bundle-output.ts b/src/compiler/bundle/bundle-output.ts index 742808c6f60..08ae331e952 100644 --- a/src/compiler/bundle/bundle-output.ts +++ b/src/compiler/bundle/bundle-output.ts @@ -151,6 +151,8 @@ export const getRollupOptions = ( onwarn: createOnWarnFn(buildCtx.diagnostics), cache: compilerCtx.rollupCache.get(bundleOpts.id), + + external: config.rollupConfig.inputOptions.external, }; return rollupOptions; diff --git a/src/compiler/config/test/validate-rollup-config.spec.ts b/src/compiler/config/test/validate-rollup-config.spec.ts index 97587c91d24..61c298282b7 100644 --- a/src/compiler/config/test/validate-rollup-config.spec.ts +++ b/src/compiler/config/test/validate-rollup-config.spec.ts @@ -56,6 +56,7 @@ describe('validateStats', () => { config.rollupConfig = { inputOptions: { context: 'window', + external: 'external_symbol', notAnOption: {}, }, outputOptions: { @@ -69,6 +70,7 @@ describe('validateStats', () => { expect(rollupConfig).toEqual({ inputOptions: { context: 'window', + external: 'external_symbol', }, outputOptions: { globals: { diff --git a/src/compiler/config/validate-rollup-config.ts b/src/compiler/config/validate-rollup-config.ts index 146ef01f8c8..1b847bf3121 100644 --- a/src/compiler/config/validate-rollup-config.ts +++ b/src/compiler/config/validate-rollup-config.ts @@ -26,7 +26,7 @@ export const validateRollupConfig = (config: d.Config): d.RollupConfig => { if (rollupConfig.inputOptions && isObject(rollupConfig.inputOptions)) { cleanRollupConfig = { ...cleanRollupConfig, - inputOptions: pluck(rollupConfig.inputOptions, ['context', 'moduleContext', 'treeshake']), + inputOptions: pluck(rollupConfig.inputOptions, ['context', 'moduleContext', 'treeshake', 'external']), }; } diff --git a/src/declarations/stencil-public-compiler.ts b/src/declarations/stencil-public-compiler.ts index e700cb99bb7..1ca24cd5cc8 100644 --- a/src/declarations/stencil-public-compiler.ts +++ b/src/declarations/stencil-public-compiler.ts @@ -1749,6 +1749,11 @@ export interface RollupInputOptions { context?: string; moduleContext?: ((id: string) => string) | { [id: string]: string }; treeshake?: boolean; + external?: + | (string | RegExp)[] + | string + | RegExp + | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined); } export interface RollupOutputOptions {