diff --git a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java index 2680673d..b4750fe6 100644 --- a/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java +++ b/j2cl-tasks/src/main/java/com/vertispan/j2cl/build/provided/BundleJarTask.java @@ -3,6 +3,7 @@ import com.google.auto.service.AutoService; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.javascript.jscomp.deps.ClosureBundler; import com.vertispan.j2cl.build.task.*; import com.vertispan.j2cl.tools.Closure; import org.apache.commons.io.FileUtils; @@ -145,11 +146,17 @@ public void finish(TaskContext taskContext) throws IOException { " elt.async = false;\n" + " document.head.appendChild(elt);\n" + "});" + "})();"; + + // Closure bundler runtime + StringBuilder runtime = new StringBuilder(); + new ClosureBundler().appendRuntimeTo(runtime); + Files.write(initialScriptFile.toPath(), Arrays.asList( defineLine, intro, scriptsArray, - outro + outro, + runtime )); } catch (IOException e) { throw new UncheckedIOException("Failed to write html import file", e); diff --git a/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Closure.java b/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Closure.java index c001ba8a..e889f391 100644 --- a/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Closure.java +++ b/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Closure.java @@ -153,6 +153,13 @@ public boolean compile( jscompArgs.add("IIFE"); } + if (compilationLevel == CompilationLevel.BUNDLE) { + // avoid injecting libraries, the runtime will be added as part of the BundleJarTask step in the + // initial download + jscompArgs.add("--inject_libraries"); + jscompArgs.add("false"); + } + for (String entrypoint : entrypoints) { jscompArgs.add("--entry_point"); jscompArgs.add(entrypoint); diff --git a/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/J2cl.java b/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/J2cl.java index 7f6cbaca..695bd28c 100644 --- a/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/J2cl.java +++ b/j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/J2cl.java @@ -1,5 +1,6 @@ package com.vertispan.j2cl.tools; +import com.google.common.collect.ImmutableList; import com.google.j2cl.common.OutputUtils; import com.google.j2cl.common.SourceUtils; import com.google.j2cl.common.Problems; @@ -11,6 +12,7 @@ import javax.annotation.Nonnull; import java.io.File; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -44,6 +46,8 @@ public boolean transpile(List sourcesToCompile, List1.6 - 0.10.0-3c97afeac - v20220502-1 + 0.11.0-9336533b6 + v20221102-1 1.11 2.7