left-icon

Aurelia Succinctly®
by Matthew Duffield

Previous
Chapter

of
A
A
A

CHAPTER 15

Features

Features


You might find that you have created a lot of custom elements, custom attributes, and custom binding behaviors, and you are getting tired of using the require tag in your HTML. Aurelia makes this very easy to do in the form of features. Typically, you will want to structure your components in a folder that allows for a clear separation from the rest of your application. A good example would be a folder called resources, and inside this folder, you would have your components like resources/my-components.

Going back to the bs-input and attach-focus components, we would have a file structure as follows:

Code Listing 129

root/

 src/

 resources/

  my-components/

  bs-input.html

  bs-input.js

  attach-focus.js

  index.js

 app.html

 app.js

 main.js

 index.html

 …

So, if we use the following structure, we can define our feature by using the last file, index.js. Let’s see what this would look like:

Code Listing 130

export function configure(config) {

 config.globalResources(

 './bs-input',

 './attach-focus',

 );

}

We are now finished with our structuring and organization. Let’s now take the final step and bring in our feature. We do this in our main.js file as follows:

Code Listing 131

import '../styles/styles.css';

import 'font-awesome/css/font-awesome.css';

import 'bootstrap/dist/css/bootstrap.css';

import 'bootstrap';

import * as Bluebird from 'bluebird';

Bluebird.config({ warnings: false });

export async function configure(aurelia) {

 aurelia.use

 .standardConfiguration()

 .developmentLogging()

 .feature('resources/my-components');

 await aurelia.start();

 aurelia.setRoot('app');

}

That’s all there is to it! You add a single line feature with the location of your components, and you get them everywhere in your application without needing to use the require tag.

Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.