Skip to content

Adding the ability to deferre asset bundling #1025

@mskorkowski

Description

@mskorkowski

Current situation

Currently Trunk's assets bundling is being run in parallel to the building stage.

Trunk's build process

This is a brief overview of Trunk's build process for the purpose of describing when hooks are executed. Please note that the exact ordering may
change in the future to add new features.

Step 1 — Read and parse the HTML file.
Step 2 — Produce a plan of all assets to be built.
Step 3 — Build all assets in parallel.
Step 4 — Finalize and write assets to staging directory.
Step 5 — Write HTML to staging directory.
Step 6 - Replace dist directory contents with staging directory contents.

The hook stages correspond to this as follows:

pre_build: takes place before step 1.
build: takes place at the same time as step 3, executing in parallel with asset builds.
post_build: takes place after step 5 and before step 6.

My issue

I have the resources which are being generated by the build script of the upstream crate to my application, which should be included into the assets. This makes it impossible to run trunk build because it expects the files assets to be reachable before build script is finished.

My proposal

Adding early_post_build stage. If somebody would use the deferred resources the new execution schema would look like

Step 1 — Read and parse the HTML file.
Step 2 — Produce a plan of all assets to be built.
Step 3 — Build all undeferred assets in parallel.
Step 3+ — Build all deferred assets in parallel.
Step 4 — Finalize and write assets to staging directory.
Step 5 — Write HTML to staging directory.
Step 6 - Replace dist directory contents with staging directory contents.

The hook stages would correspond now

pre_build: takes place before step 1.
build: takes place at the same time as step 3, executing in parallel with asset builds.
early_post_build: starts at step 3+ - 5
post_build: takes place after step 5 and before step 6.

To mark the resource as deferred in index.html it would be required to add the deferred boolean attribute

<link data-trunk rel="{type}" href="{path}" deffered  ..other options here.. />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions