From 99498e1a7cd5b00517589616daf6fd884ebb6ca9 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Tue, 7 Nov 2023 17:46:11 +0100 Subject: [PATCH] Allow external-imports --- .../web/bundler/deployment/WebBundlerConfig.java | 7 +++++++ .../bundler/deployment/WebBundlerProcessor.java | 14 ++++++++++---- .../ROOT/pages/includes/quarkus-web-bundler.adoc | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerConfig.java b/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerConfig.java index 9edaa55..7d5348a 100644 --- a/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerConfig.java +++ b/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerConfig.java @@ -5,6 +5,7 @@ import static java.util.function.Predicate.not; import java.nio.charset.Charset; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -66,6 +67,12 @@ default String fromWebRoot(String dir) { */ LoadersConfig loaders(); + /** + * This defines the list of external paths for esbuild (https://esbuild.github.io/api/#external). + * Instead of being bundled, the import will be preserved. + */ + Optional> externalImports(); + /** * Configure how dependencies are collected */ diff --git a/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerProcessor.java b/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerProcessor.java index fc5f8e0..52480fa 100644 --- a/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/web/bundler/deployment/WebBundlerProcessor.java @@ -154,13 +154,19 @@ void bundle(WebBundlerConfig config, final Map loaders = computeLoaders(config); loaders.put(".scss", EsBuildConfig.Loader.CSS); + final EsBuildConfigBuilder esBuildConfigBuilder = new EsBuildConfigBuilder() + .loader(loaders) + .addExternal(surroundWithSlashes(config.staticDir()) + "*") + .minify(launchMode.getLaunchMode().equals(LaunchMode.NORMAL)); + if (config.externalImports().isPresent()) { + for (String e : config.externalImports().get()) { + esBuildConfigBuilder.addExternal(e); + } + } final BundleOptionsBuilder options = new BundleOptionsBuilder() .setWorkFolder(targetDir) .withDependencies(webDependencies.getDependencies()) - .withEsConfig(new EsBuildConfigBuilder() - .loader(loaders) - .addExternal(surroundWithSlashes(config.staticDir()) + "*") - .minify(launchMode.getLaunchMode().equals(LaunchMode.NORMAL)).build()) + .withEsConfig(esBuildConfigBuilder.build()) .withType(type); int addedEntryPoints = 0; for (EntryPointBuildItem entryPoint : entryPoints) { diff --git a/docs/modules/ROOT/pages/includes/quarkus-web-bundler.adoc b/docs/modules/ROOT/pages/includes/quarkus-web-bundler.adoc index bfbd57f..0757f06 100644 --- a/docs/modules/ROOT/pages/includes/quarkus-web-bundler.adoc +++ b/docs/modules/ROOT/pages/includes/quarkus-web-bundler.adoc @@ -362,6 +362,22 @@ endif::add-copy-button-to-env-var[] |`json` +a|icon:lock[title=Fixed at build time] [[quarkus-web-bundler_quarkus.web-bundler.external-imports]]`link:#quarkus-web-bundler_quarkus.web-bundler.external-imports[quarkus.web-bundler.external-imports]` + +[.description] +-- +This defines the list of external paths for esbuild (https://esbuild.github.io/api/++#++external). Instead of being bundled, the import will be preserved. + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++QUARKUS_WEB_BUNDLER_EXTERNAL_IMPORTS+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++QUARKUS_WEB_BUNDLER_EXTERNAL_IMPORTS+++` +endif::add-copy-button-to-env-var[] +--|list of string +| + + a|icon:lock[title=Fixed at build time] [[quarkus-web-bundler_quarkus.web-bundler.dependencies.type]]`link:#quarkus-web-bundler_quarkus.web-bundler.dependencies.type[quarkus.web-bundler.dependencies.type]` [.description]