View Resource pipeline
The View Resource Pipeline is the mechanism Aurelia uses to discover, load, and process all the resources your templates depend on. This includes custom elements, custom attributes, value converters, binding behaviors, and even CSS files.
The <require> Element
The primary way to import resources into a template is with the <require> element:
<template>
<require from="bootstrap/css/bootstrap.min.css"></require>
<p class="lead">Hello, World!</p>
<p>Lorem Ipsum...</p>
</template>The <require> tag isn't limited to HTML or view models — it can also handle CSS files. Aurelia's View Resource Pipeline intelligently recognizes and processes these different resource types based on their file extension.
Importing Custom Elements
<template>
<require from="./my-component"></require>
<my-component></my-component>
</template>Importing Custom Attributes
<template>
<require from="./tooltip"></require>
<p tooltip="Hello!">Hover me</p>
</template>Importing Value Converters
Importing CSS
CSS imported via <require> is scoped and processed by the pipeline:
Aliasing with as
You can alias an imported resource using the as attribute. This is useful when a resource name conflicts with another or when you want a more descriptive name:
Global Resources
Instead of importing resources in every template, you can register them globally in your application's startup configuration:
Global resources are available in all templates without a <require> import.
Resource Conventions
Aurelia uses naming conventions to determine what type of resource a file contains:
Custom elements — A class with a corresponding
.htmltemplate file (e.g.,nav-bar.js+nav-bar.html)Custom attributes — A class decorated with
@customAttributeor following the*CustomAttributenaming conventionValue converters — A class following the
*ValueConverternaming convention (e.g.,DateFormatValueConverter)Binding behaviors — A class following the
*BindingBehaviornaming convention (e.g.,ThrottleBindingBehavior)
Extending the Pipeline
You can create custom view resource types by implementing a ViewEngineHooks class. This allows you to intercept and transform resources as they flow through the pipeline:
Register your hooks as a global resource:
Last updated
Was this helpful?