Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Bundling envs #228

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>`
|

|===
Loading