{"id":23174896,"url":"https://github.com/larsgrefer/dart-sass-java","last_synced_at":"2025-06-15T03:05:42.340Z","repository":{"id":37613444,"uuid":"296478981","full_name":"larsgrefer/dart-sass-java","owner":"larsgrefer","description":"Java Implementation of an embedded-sass host","archived":false,"fork":false,"pushed_at":"2024-12-06T18:28:13.000Z","size":1358,"stargazers_count":26,"open_issues_count":8,"forks_count":4,"subscribers_count":3,"default_branch":"3.x","last_synced_at":"2024-12-06T20:41:31.574Z","etag":null,"topics":["dart-sass","java","sass"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/larsgrefer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-18T01:10:53.000Z","updated_at":"2024-12-06T18:28:09.000Z","dependencies_parsed_at":"2023-10-17T06:03:04.472Z","dependency_job_id":"6b8eab80-a301-4c84-bfd4-10fe1108f327","html_url":"https://github.com/larsgrefer/dart-sass-java","commit_stats":null,"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsgrefer%2Fdart-sass-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsgrefer%2Fdart-sass-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsgrefer%2Fdart-sass-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsgrefer%2Fdart-sass-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/larsgrefer","download_url":"https://codeload.github.com/larsgrefer/dart-sass-java/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230224362,"owners_count":18192874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart-sass","java","sass"],"created_at":"2024-12-18T05:33:53.566Z","updated_at":"2024-12-18T05:33:54.187Z","avatar_url":"https://github.com/larsgrefer.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dart-sass-java\n\n[![Java CI with Gradle](https://github.com/larsgrefer/dart-sass-java/actions/workflows/gradle.yml/badge.svg)](https://github.com/larsgrefer/dart-sass-java/actions/workflows/gradle.yml)\n[![codecov](https://codecov.io/gh/larsgrefer/dart-sass-java/branch/3.x/graph/badge.svg?token=WPUF2AWJVF)](https://codecov.io/gh/larsgrefer/dart-sass-java)\n\nThis is a Java library that implements the host side of the [Embedded Sass\nprotocol](https://github.com/sass/sass/blob/main/spec/embedded-protocol.md)\n\nReleases can be found on [Maven Central](https://mvnrepository.com/artifact/de.larsgrefer.sass).\n\n## Modules\n\n### `sass-embedded-protcol`\n\nThis module contains the Java DTO-classes for the [Embedded Sass protocol](https://github.com/sass/sass/blob/main/spec/embedded-protocol.md) as produced by protoc.\n\n### `sass-embedded-host`\n\nThis module contains the actual host-implementation.\n\n### `sass-embedded-bundled`\n\nThis module contains the embedded dart-sass executables.\n\n### `sass-embedded-spring5`\n\nSpring Framework 5, JavaEE specific classes.\n\n### `sass-embedded-spring6`\n\nSpring Framework 6, JakartaEE specific classes.\n\n## Basic usage\n\nFirst import `sass-embedded-host` as dependency into your project. For example using Maven add the following XML to your dependencies section:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ede.larsgrefer.sass\u003c/groupId\u003e\n    \u003cartifactId\u003esass-embedded-host\u003c/artifactId\u003e\n    \u003c!-- replace x.y.z with the desidered version --\u003e\n    \u003cversion\u003ex.y.z\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nNow you can instantiate *SassCompiler* to compile your sass file: \n\n```java\ntry (SassCompiler sassCompiler = SassCompilerFactory.bundled()) {\n    CompileSuccess compileSuccess = sassCompiler.compileFile(new File(\"src/main/resources/foo/bar.scss\"));\n\n    //get compiled css\n    String css = compileSuccess.getCss();\n}\n```\n\n## Advanced usage with `WebJars`\n\nWebJars is a project aimed to provide client-side libraries distributions as Maven dependency. Using classpath URLs we can read SCSS files directly from our WebJars dependency. For example let's say we are using the WebJars dependency for Bootstrap 5.1.3:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.webjars.npm\u003c/groupId\u003e\n    \u003cartifactId\u003ebootstrap\u003c/artifactId\u003e\n    \u003cversion\u003e5.1.3\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nThe following code compiles the main Bootstrap SCSS file into css:\n\n```java\nURL resource = getClass().getResource(\"/META-INF/resources/webjars/bootstrap/5.3.0/scss/bootstrap.scss\");\nCompileSuccess compileSuccess = sassCompiler.compile(resource);\nString css = compileSuccess.getCss(); \n```\n\nFiles form WebJars can be also imported directly from SCSS files. Let's say for example that we would like to customize Bootstrap with our favorite colors. We could create a custom SCSS file (for example: src/main/resources/custom-bootstrap.scss) with this content:\n\n```scss\n//VARIABLE OVERRIDING\n$primary: #712cf9;\n$secondary: #f19027;\n\n//INCLUDING MAIN BOOTSTRAP SCSSS\n@import \"META-INF/resources/webjars/bootstrap/5.3.0/scss/bootstrap.scss\";\n```\n\nTo compile the file above we need to register a *WebjarsImporter* into our compiler:\n\n```java\ntry (SassCompiler sassCompiler = SassCompilerFactory.bundled()) {\n    sassCompiler.registerImporter(new WebjarsImporter().autoCanonicalize());\n\n    URL resource = getClass().getResource(\"/custom-bootstrap.scss\");\n    CompileSuccess compileSuccess = sassCompiler.compile(resource);\n\n    //custom Bootstrap css\n    String css = compileSuccess.getCss();\n}\n```\n\n## Performance and Thread safety\n\nBy default - using `SassCompilerFactory.bundled()` - each created `SassCompiler` gets a fresh `CompilerConnection` based on a newly spawned subprocess of the embedded dart-sass binary.\n\nThis has two consequences:\n\n1. Creating a new `SassCompiler` is a rather expensive operation, so try to re-use one (or few) instances instead of creating a new one for each compilation.\n2. Make sure to `close()` the `SassCompiler` when you`re done with it, so the subprocess can be stopped and the allocated memory can be freed.\n\nThe important parts of the communication with the actual compiler are `synchronized` on the `CompilerConnection` object, so it should be safe to use a single `SassCompiler` instance in a multithreaded environment. For better performance you might want to create multiple instances in order to avoid threads blocking each other, but keep in mind that creating new instances is still an expensive operation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarsgrefer%2Fdart-sass-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flarsgrefer%2Fdart-sass-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarsgrefer%2Fdart-sass-java/lists"}