Packaging and Reusing Aurelia View ViewModel Components

I have a basic widget ( widget.js

, widget.html

and widget.css

) that I use through a template:

<template>
  <require from="./widget"/>
  <widget/> 
</template>

      

What steps need to be taken to reuse this component in aurelia projects?

I haven't done a package before, but I would like to just push widget.js, widget.html and widget.css to a github repository and then define a JSPM package for it. I know I can define main = "widget.js", but I'm not sure if I can also package the html file. I also don't know if aurelia can "require" a template from the jspm package.

+3


source to share


1 answer


To reuse such components, you can create an Aurelia plugin. A plugin is basically a reusable piece that can be a single codebase used across applications.

You can run your plugin from this skeleton -

https://github.com/aurelia/skeleton-plugin



In a nutshell, all you need to do is download the plugin source code and replace hello-world.js

it hello-world.html

with your own code in the src folder.

index.js

is where the plugin setup method is implemented. This is where you can make it available to consumers. Typically, most plugins use globalizeResources

so you can prevent consumers from having require

it in every view it uses, but that's up to you with its plugin :)

+1


source







All Articles