#html #inline #assets #build

inline_assets

A Rust library for inlining Javascript, CSS, and font files into your html files for easy distribution

7 releases (4 breaking)

0.5.0 Feb 19, 2022
0.4.1 Sep 20, 2019
0.3.1 Jul 15, 2018
0.2.1 Jul 2, 2018
0.1.4 Jul 2, 2018

#45 in #inline

Download history 43/week @ 2024-07-29 13/week @ 2024-09-23

74 downloads per month
Used in meyl

MIT license

14KB
229 lines

inline-assets-rs

Build Status Docs.rs MIT licensed

A Rust library for inlining Javascript, CSS, and font files into your html files for easy distribution. This also changes url(local_path) in the css to be relative to the html file.

Originally intended to be used in build scripts of web_view projects. The output can also be able to be piped into minifier-rs to save space.

Usage:

Usage is really simple, just call inline_assets::inline_html_string(file_path, inline_assets::Config::default()), with the html file path.

The config currently provides 2 options (with the default being both enabled):

  • inline_fonts: Whether or not to inline fonts in the css as base64.
  • remove_new_lines: Replace \r and \r\n with a space character. Useful to keep line numbers the same in the output to help with debugging.

Look in the example folder for a CLI binary example.

All font files should work if font format is set correctly. i.e.src: url(font-file) format(font-format)

To import CSS recursively, use @import url(path_to_another_css_file); in your css files. Multiple imports of the same CSS file will only be imported once.

TODO:

  • Support inlining images

Dependencies

~6–12MB
~142K SLoC