Skip to content

Commit

Permalink
Merge pull request #228 from ia3andy/envs
Browse files Browse the repository at this point in the history
Introduce Bundling envs
  • Loading branch information
phillip-kruger authored May 27, 2024
2 parents f140ecc + 83941d2 commit 7c62300
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.nio.charset.Charset;
import java.util.*;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
Expand Down Expand Up @@ -134,6 +135,25 @@ interface BundlingConfig {
@WithDefault("linked")
String sourceMap();

/**
* List of environments for the bundle
*/
Map<String, String> envs();

default Map<String, String> safeEnvs() {
if (envs().isEmpty()) {
return Map.of();
}
return envs()
.entrySet()
.stream()
.collect(Collectors.toMap(e -> safe(e.getKey()), e -> "'" + safe(e.getValue()) + "'"));
}

static String safe(String v) {
return v.replaceAll("^[^a-zA-Z_$]|[^0-9a-zA-Z_$]", "_");
}

default boolean sourceMapEnabled() {
return "linked".equalsIgnoreCase(sourceMap())
|| "true".equalsIgnoreCase(sourceMap())
Expand All @@ -152,6 +172,7 @@ static boolean isEqual(BundlingConfig c1, BundlingConfig c2) {
return Objects.equals(c1.splitting(), c2.splitting())
&& LoadersConfig.isEqual(c1.loaders(), c2.loaders())
&& Objects.equals(c1.external(), c2.external())
&& Objects.equals(c1.envs(), c2.envs())
&& Objects.equals(c1.sourceMap(), c2.sourceMap());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ ReadyForBundlingBuildItem prepareForBundling(WebBundlerConfig config,
+ "'")
.fixedEntryNames();
}
if (!config.bundling().envs().isEmpty()) {
esBuildConfigBuilder.define(config.bundling().safeEnvs());
}
if (config.bundling().external().isPresent()) {
for (String e : config.bundling().external().get()) {
esBuildConfigBuilder.addExternal(e);
Expand Down
1 change: 1 addition & 0 deletions deployment/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
quarkus.web-bundler.dependencies.compile-only=false
quarkus.web-bundler.bundle-redirect=true
quarkus.web-bundler.bundling.envs.HELLO_ENV=world
quarkus.log.category."io.quarkiverse.web.bundler".level=DEBUG
quarkus.log.category."io.mvnpm.esbuild".level=DEBUG
quarkus.http.root-path=/foo/bar
2 changes: 1 addition & 1 deletion deployment/src/test/resources/web/app/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from 'jquery';

$(document).ready(function() {
console.log("hello world");
console.log("hello " + HELLO_ENV);
});
17 changes: 17 additions & 0 deletions docs/modules/ROOT/pages/includes/quarkus-web-bundler.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,21 @@ endif::add-copy-button-to-env-var[]
--|boolean
|`false`


a|icon:lock[title=Fixed at build time] [[quarkus-web-bundler_quarkus-web-bundler-bundling-envs-envs]]`link:#quarkus-web-bundler_quarkus-web-bundler-bundling-envs-envs[quarkus.web-bundler.bundling.envs]`


[.description]
--
List of environments for the bundle

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_WEB_BUNDLER_BUNDLING_ENVS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_WEB_BUNDLER_BUNDLING_ENVS+++`
endif::add-copy-button-to-env-var[]
--|`Map<String,String>`
|

|===

0 comments on commit 7c62300

Please sign in to comment.