{"id":32284067,"url":"https://github.com/pschiffmann/inject-assets-builder.dart","last_synced_at":"2026-02-21T02:39:02.503Z","repository":{"id":56833047,"uuid":"155689251","full_name":"pschiffmann/inject-assets-builder.dart","owner":"pschiffmann","description":"A builder that makes it possible for a package to access files from packages depending on it.","archived":false,"fork":false,"pushed_at":"2018-11-08T17:54:16.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T01:28:54.509Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pub.dartlang.org/packages/inject_assets_builder","language":"Dart","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/pschiffmann.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-01T09:07:13.000Z","updated_at":"2019-09-21T12:17:55.000Z","dependencies_parsed_at":"2022-09-08T07:50:36.963Z","dependency_job_id":null,"html_url":"https://github.com/pschiffmann/inject-assets-builder.dart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pschiffmann/inject-assets-builder.dart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschiffmann%2Finject-assets-builder.dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschiffmann%2Finject-assets-builder.dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschiffmann%2Finject-assets-builder.dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschiffmann%2Finject-assets-builder.dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pschiffmann","download_url":"https://codeload.github.com/pschiffmann/inject-assets-builder.dart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschiffmann%2Finject-assets-builder.dart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29604137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T04:38:07.383Z","status":"ssl_error","status_checked_at":"2026-02-19T04:35:50.016Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-10-23T01:26:40.983Z","updated_at":"2026-02-21T02:39:02.496Z","avatar_url":"https://github.com/pschiffmann.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"inject assets builder\n=====================\n\n[![Build Status](https://travis-ci.com/pschiffmann/inject-assets-builder.dart.svg?branch=master)](https://travis-ci.com/pschiffmann/inject-assets-builder.dart)\n\nThis package contains a [builder][build] that makes it possible for a package to access files from packages depending on it.\n\n_The build package uses the syntax `pkg|lib/foo.txt` to refer to the file `foo.txt` in the `lib/` directory of package `pkg`. In this document, I'll use the same syntax for all references to files to avoid ambiguity._\n\n# Example use case\n\n_I'll use this example to illustrate how the builder works, but the injection mechanism is not limited to SASS files, as explained below. In this document, I'll refer to a package that is used as a dependency as `dep`, and to a package consuming `dep` and injecting assets into it as `app`._\n\nI work on a package that contains Angular components, and a couple of web apps that use these components. Each app has a different design, so I need to set some CSS properties of the components from within the app packages. The component styles are compiled from SASS, so the most convenient solution (for a consumer of `dep`) would be if `dep` read these values from a file in `app`. I want that file to be `app|lib/_variables.scss`.\n\n`dep` can't simply import a file from `app`, because SASS import paths must be statically known, and `dep` could be used by multiple apps. That's where this builder comes into play.\n\nThis package contains a builder `inject_scss_files` that looks for a provisional `dep|lib/_variables.default.scss` file and creates the final `dep|lib/_variables.scss` file. The contents of `dep|lib/_variables.scss` are copied from `app|lib/_variables.scss`, but the source file is configurable in the build configuration. This way, a package `app2` could set `app2|lib/_variables.scss` as the source.\n\nNow, components in `dep` can use the statically known import path `dep|lib/_variables.scss`, but will access the file contents from `app` at build time.\n\n# Injecting SASS files\n\nThese are all the required steps to implement this use case.\nIn `dep`, add this package to the dependencies. Also add a dependency on [build_config][build config] to ensure compatibility with consumers of your package.\nThen, create a `dep|build.yaml` file with the following content:\n\n```yaml\ntargets:\n  # When a package depending on `dep` is built, this build target is\n  # automatically built too.\n  $default:\n    builders:\n      inject_assets_builder|inject_scss_files:\n        enabled: true\n```\n\nIn `app|build.yaml`, specify which assets should be injected for the `.default` assets:\n\n```yaml\nglobal_options:\n  inject_assets_builder|inject_scss_files:\n    options:\n      asset_overrides:\n        'dep|lib/_variables.default.scss': 'app|lib/_variables.scss'\n```\n\nIf you don't specify a source for a `.default` asset, the asset itself will be used as the final file. This means that a consumer doesn't have to configure anything if they are satisfied with the default contents.\n\n_Side note on SASS files:  `app|lib/_variables.scss` can import the default file with `@import 'package:dep/variables.default';`. Then, you only need to assign those variables you actually want to change._\n\n# Injecting assets with other extensions\n\nThe Dart build system requires that builders statically declare all the file extensions they run on. This makes it impossible to process all `.default.*` files in a single builder. If you need to inject assets that don't end in `.scss` or `.sass`, you need to declare your own builder. You can use `inject_asset_builder|build.yaml` as a template; you should only need to change the `build_extensions` and `file_extensions` configuration and the builder name. Then reference it with `$yourPackage|$builderName` in `builders` and `global_options`.\n\n[build]: https://pub.dartlang.org/packages/build\n[build config]: https://pub.dartlang.org/packages/build_config\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpschiffmann%2Finject-assets-builder.dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpschiffmann%2Finject-assets-builder.dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpschiffmann%2Finject-assets-builder.dart/lists"}