3

I have a basic widget (widget.js, widget.html and widget.css) that I am using via a template:

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

What steps do I need to take to reuse this component across aurelia projects?

I've not made a package before, but my understanding would be to simply commit widget.js, widget.html and widget.css to a github repository, 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. Nor do I know if aurelia can "require" a template from a jspm package.

4

1 回答 1

1

要重用这样的组件,您可以创建一个 Aurelia 插件。插件基本上是一些可重用的部分,可以是跨应用程序共享的单个代码库。

你可以从这个骨架开始你的插件 -

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

简而言之,您需要做的就是下载插件源代码并将 和 替换hello-world.jshello-world.htmlsrc 文件夹中的自定义代码。

index.js是插件的配置方法实现的地方。这是您将其提供给消费者的地方。通常,大多数插件使用globalizeResources这样您就可以防止消费者在使用require它的每个视图中都必须使用它,但这取决于您,因为它是您的插件:)

于 2015-06-24T18:06:15.037 回答