Skip to content

Commit

Permalink
New esbuild-java with scss-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Jan 26, 2024
1 parent 48ed0f4 commit 9f44015
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.*;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -30,25 +20,14 @@

import io.mvnpm.esbuild.BundleException;
import io.mvnpm.esbuild.Bundler;
import io.mvnpm.esbuild.model.BundleOptions;
import io.mvnpm.esbuild.model.BundleOptionsBuilder;
import io.mvnpm.esbuild.model.BundleResult;
import io.mvnpm.esbuild.model.EsBuildConfig;
import io.mvnpm.esbuild.model.EsBuildConfigBuilder;
import io.mvnpm.esbuild.model.WebDependency;
import io.mvnpm.esbuild.model.*;
import io.quarkiverse.web.bundler.deployment.WebBundlerConfig.LoadersConfig;
import io.quarkiverse.web.bundler.deployment.items.BundleConfigAssetsBuildItem;
import io.quarkiverse.web.bundler.deployment.items.BundleWebAsset;
import io.quarkiverse.web.bundler.deployment.items.EntryPointBuildItem;
import io.quarkiverse.web.bundler.deployment.items.GeneratedBundleBuildItem;
import io.quarkiverse.web.bundler.deployment.items.WebAsset;
import io.quarkiverse.web.bundler.deployment.items.WebDependenciesBuildItem;
import io.quarkiverse.web.bundler.deployment.items.*;
import io.quarkiverse.web.bundler.deployment.staticresources.GeneratedStaticResourceBuildItem;
import io.quarkiverse.web.bundler.deployment.staticresources.GeneratedStaticResourceBuildItem.WatchMode;
import io.quarkiverse.web.bundler.runtime.Bundle;
import io.quarkiverse.web.bundler.runtime.BundleRedirectHandlerRecorder;
import io.quarkiverse.web.bundler.runtime.WebBundlerBuildRecorder;
import io.quarkiverse.web.bundler.sass.SassBuildTimeCompiler;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.builder.BuildException;
Expand Down Expand Up @@ -147,7 +126,6 @@ void bundle(WebBundlerConfig config,
}

final Map<String, EsBuildConfig.Loader> loaders = computeLoaders(config);
loaders.put(".scss", EsBuildConfig.Loader.CSS);
final EsBuildConfigBuilder esBuildConfigBuilder = new EsBuildConfigBuilder()
.loader(loaders)
.publicPath(config.publicBundlePath())
Expand Down Expand Up @@ -230,14 +208,6 @@ void bundle(WebBundlerConfig config,
}
}
final long startedBundling = Instant.now().toEpochMilli();
// SCSS conversion
if (!isLiveReload || hasScssChange) {
try (Stream<Path> stream = Files.find(targetDir, Integer.MAX_VALUE,
(p, a) -> !p.toString().contains("node_modules")
&& isCompiledSassFile(p.getFileName().toString()))) {
stream.forEach(p -> convertToScss(p, targetDir));
}
}
final BundleResult result = Bundler.bundle(options, false);
if (!result.result().output().isBlank()) {
LOGGER.debugf(result.result().output());
Expand Down Expand Up @@ -295,18 +265,6 @@ private Map<String, EsBuildConfig.Loader> computeLoaders(WebBundlerConfig config
return loaders;
}

static void convertToScss(Path file, Path root) {
LOGGER.debugf("Converting %s to css", file);
String content = SassBuildTimeCompiler.convertScss(file, root, (s, s2) -> {
});
try {
Files.writeString(file, content, StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

void handleBundleDistDir(WebBundlerConfig config, BuildProducer<GeneratedBundleBuildItem> generatedBundleProducer,
BuildProducer<GeneratedStaticResourceBuildItem> staticResourceProducer, Path bundleDir, Long started,
boolean changed) {
Expand Down Expand Up @@ -378,14 +336,6 @@ void initBundleRedirect(WebBundlerConfig config, BuildProducer<RouteBuildItem> r
}
}

/**
* Returns true if the given filename (not path) does not start with _
* and ends with either .sass or .scss case-insensitive
*/
public static boolean isCompiledSassFile(String filename) {
return !filename.startsWith("_") && isSassFile(filename);
}

public static boolean isImportSassFile(String filename) {
return filename.startsWith("_") && isSassFile(filename);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ WebDependenciesBuildItem collectDependencies(LaunchModeBuildItem launchMode,
}

private void checkScope(LaunchModeBuildItem launchMode, ResolvedDependency d, WebBundlerConfig config) {
if (!launchMode.isTest() && config.dependencies().compileOnly() && d.isRuntimeCp()) {
if (!launchMode.getLaunchMode().isDevOrTest() && config.dependencies().compileOnly() && d.isRuntimeCp()) {
throw new ConfigurationException(
("The Web Bundler is configured to only include compileOnly web dependencies, but %s is set as runtime." +
" Use a compile only scope (e.g. provided) or set quarkus.web-bundler.dependencies.compile-only=false to allow runtime web dependencies.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


.calendar {
h1 {
background-color: red;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
color: red;
}
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.7.0</quarkus.version>

<esbuild-java.version>1.1.2</esbuild-java.version>
<esbuild-java.version>999-SNAPSHOT</esbuild-java.version>
<scrimage-core.version>4.1.1</scrimage-core.version>
<yuicompressor.version>2.4.8</yuicompressor.version>
</properties>
Expand Down

0 comments on commit 9f44015

Please sign in to comment.