Plugin Development

Plugin Entry Point

The plugin entry point is typically located at src/index.js (or src/index.ts for TypeScript). It exports a configure function that Aurelia calls when the plugin is loaded:

import { PLATFORM } from 'aurelia-pal';

export function configure(config) {
  // Plugin configuration logic
  config.globalResources([
    PLATFORM.moduleName('./elements/my-custom-element'),
    PLATFORM.moduleName('./value-converters/my-value-converter')
  ]);
}

Configuration Methods

The configure function receives a FrameworkConfiguration object with several important methods:

Method
Description
Example

globalResources()

Register global resources like elements, attributes, converters

config.globalResources(PLATFORM.moduleName('./my-element'))

plugin()

Load and configure other plugins

config.plugin(PLATFORM.moduleName('aurelia-dialog'))

singleton()

Register a singleton in the dependency injection container

config.singleton(MyService, MyService)

transient()

Register a transient dependency

config.transient(MyService, MyService)

Creating Resources

Custom Elements

Generate a custom element using Aurelia CLI:

Example custom element:

Custom Attributes

Generate a custom attribute:

Example custom attribute:

Value Converters

Generate a value converter:

Example value converter:

Binding Behaviors

Generate a binding behavior:

Example binding behavior:

Registering Resources

After creating resources, register them in the plugin's entry point:

Development Workflow

Running the Dev App

Start the development application:

This command:

  • Launches the development application

  • Automatically opens it in your default browser

  • Provides live reloading during development

Testing

Running Tests

circle-info

Recommended Testing Frameworks:

  • Karma: Best for real browser testing

  • Jest: Faster, but uses a simulated browser environment

Writing Tests

Example unit test:

Managing Dependencies

Internal Dependencies

  • Use PLATFORM.moduleName() for module references

  • Avoid direct imports in the plugin's entry point

External Dependencies

In package.json:

circle-exclamation
  1. Generate resources

  2. Implement functionality

  3. Write tests

  4. Run dev app to verify

  5. Iterate and refine

Last updated

Was this helpful?