inject_assets_builder 1.0.0+1

  • Readme
  • Changelog
  • Installing
  • 45

inject assets builder #

Build Status

This package contains a builder that makes it possible for a package to access files from packages depending on it.

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.

Example use case #

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.

I 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.

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.

This 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.

Now, 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.

Injecting SASS files #

These are all the required steps to implement this use case. In dep, add this package to the dependencies. Also add a dependency on build_config to ensure compatibility with consumers of your package. Then, create a dep|build.yaml file with the following content:

  # When a package depending on `dep` is built, this build target is
  # automatically built too.
        enabled: true

In app|build.yaml, specify which assets should be injected for the .default assets:

        'dep|lib/_variables.default.scss': 'app|lib/_variables.scss'

If 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.

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.

Injecting assets with other extensions #

The 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.


1.0.0+1 #


1.0.0 #

Initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  inject_assets_builder: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:inject_assets_builder/builder.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21


Detected platforms: Flutter, other

Platform components identified in package: build, io.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (build_config).

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and inject_assets_builder.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.

Package is getting outdated. (-3.56 points)

The package was last published 54 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
build >=0.12.7 <2.0.0 1.2.2
build_config ^0.3.1+3 0.3.2 0.4.1+1
meta >=0.9.0 <2.0.0 1.1.8
Transitive dependencies
_fe_analyzer_shared 1.0.0
analyzer 0.39.1
args 1.5.2
async 2.4.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
front_end 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
json_annotation 2.4.0 3.0.0
kernel 0.3.29
logging 0.11.3+2
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
build_test ^0.10.3+3
test ^1.0.0