+++ title = "Assets" description = "Assets" weight = 1 +++ Declaring assets to be processed by Trunk is simple and extensible. # Link Asset Types All link assets to be processed by Trunk must follow these three rules: - Must be declared as a valid HTML `link` tag. - Must have the attribute `data-trunk`. - Must have the attribute `rel="{type}"`, where `{type}` is one of the asset types listed below. This will typically look like: ``. Each asset type described below specifies the required and optional attributes for its asset type. All `` HTML elements will be replaced with the output HTML of the associated pipeline. ## rust ✅ `rel="rust"`: Trunk will compile the specified Cargo project as WASM and load it. This is optional. If not specified, Trunk will look for a `Cargo.toml` in the parent directory of the source HTML file. - `href`: (optional) the path to the `Cargo.toml` of the Rust project. If a directory is specified, then Trunk will look for the `Cargo.toml` in the given directory. If no value is specified, then Trunk will look for a `Cargo.toml` in the parent directory of the source HTML file. - `data-target-name`: (optional) the name of the target artifact to load. If the Cargo project has multiple targets (binaries and library), this value can be used to select which one should be used by trunk. - `data-bin`: (optional) the name of the binary to compile and load. If the Cargo project has multiple binaries, this value can be used to specify that a specific binary should be compiled (using `--bin`) and used by trunk. This implicitly includes `data-target-name`. - `data-type`: (optional) specifies how the binary should be loaded into the project. Can be set to `main` or `worker`. `main` is the default. There can only be one `main` link. For workers a wasm-bindgen javascript wrapper and the wasm file (with `_bg.wasm` suffix) is created, named after the binary name (if provided) or project name. See one of the webworker examples on how to load them. - `data-cargo-features`: (optional) Space or comma separated list of cargo features to activate. - `data-cargo-no-default-features`: (optional) Disables the default Cargo features. - `data-cargo-all-features`: (optional) Enables all Cargo features. - Neither compatible with `data-cargo-features` nor `data-cargo-no-default-features`. - `data-wasm-opt`: (optional) run wasm-opt with the set optimization level. The possible values are `0`, `1`, `2`, `3`, `4`, `s`, `z` or an _empty value_ for wasm-opt's default. Set this option to `0` to disable wasm-opt explicitly. The values `1-4` are increasingly stronger optimization levels for speed. `s` and `z` (z means more optimization) optimize for binary size instead. Only used in `--release` mode. - `data-wasm-opt-params`: (optional) run wasm-opt with the additional params. Only used in `--release` mode. - `data-keep-debug`: (optional) instruct `wasm-bindgen` to preserve debug info in the final WASM output, even for `--release` mode. This may conflict with the use of wasm-opt, so to be sure, it is recommended to set `data-wasm-opt="0"` when using this option. - `data-no-demangle`: (optional) instruct `wasm-bindgen` to not demangle Rust symbol names. - `data-reference-types`: (optional) instruct `wasm-bindgen` to enable [reference types](https://rustwasm.github.io/docs/wasm-bindgen/reference/reference-types.html). - `data-weak-refs`: (optional) instruct `wasm-bindgen` to enable [weak references](https://rustwasm.github.io/docs/wasm-bindgen/reference/weak-references.html). - `data-typescript`: (optional) instruct `wasm-bindgen` to output Typescript bindings. Defaults to false. - `data-bindgen-target`: (optional) specifies the value of the `wasm-bindgen` [flag `--target`](https://rustwasm.github.io/wasm-bindgen/reference/deployment.html) (see link for possible values). Defaults to `no-modules`. The main use-case is to switch to `web` with `data-type="worker"` which reduces backwards [compatibility](https://caniuse.com/mdn-api_worker_worker_ecmascript_modules) but with some [advantages](https://rustwasm.github.io/wasm-bindgen/examples/without-a-bundler.html?highlight=no-modules#using-the-older---target-no-modules). - `data-loader-shim`: (optional) instruct `trunk` to create a loader shim for web workers. Defaults to false. - `data-cross-origin`: (optional) the `crossorigin` setting when loading the code & script resources. Defaults to plain `anonymous`. - `data-integrity`: (optional) the `integrity` digest type for code & script resources. Defaults to plain `sha384`. - `data-wasm-no-import`: (optional) by default, Trunk will generate an import of functions exported from Rust. Enabling this flag disables this feature. Defaults to false. - `data-wasm-import-name`: (optional) the name of the global variable where the functions imported from WASM will be available (under the `window` object). Defaults to `wasmBindings` (which makes them available via `window.wasmBindings.`). - `data-target-path`: (optional) Path where the output is placed inside the dist dir. If not present, the directory is placed in the dist root. The path must be a relative path without `..`. ## sass/scss ✅ `rel="sass"` or `rel="scss"`: Trunk uses the official [dart-sass](https://github.com/sass/dart-sass) for compilation. Just link to your sass files from your source HTML, and Trunk will handle the rest. This content is hashed for cache control. The `href` attribute must be included in the link pointing to the sass/scss file to be processed. - `data-inline`: (optional) this attribute will inline the compiled CSS from the SASS/SCSS file into a `