Aurelia 插件和功能有什么区别?

What is the difference between Aurelia Plugin and Feature?

我正在尝试为我的应用程序注册几个插件,但我不确定应该如何完成。

我拥有的插件包括两个 ValueConverters 和我通过 JSPM 安装的 gooy/aurelia-animator-tinyanimate

这是我当前的实现:

resources\index.ts/js

export function configure(aurelia) {
  aurelia.globalResources('../from-now', '../date-format');
}

main.ts/js(这是app的入口)

import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia): void {
        aurelia.use
            .standardConfiguration()
            .developmentLogging()
            .plugin('resources/index', 'gooy/aurelia-animator-tinyanimate'); 

        aurelia.start().then(function () { return aurelia.setRoot('views/app'); });
}

转换器正在工作,但我没有看到要加载的 tinyanimate

基于以上,我有以下问题:

  1. 如何将 gooy/aurelia-animator-tinyanimate 移动到 index.js 文件?
  2. plugin()feature()有什么区别?

功能与插件基本相同,只是它们位于您自己的源代码树中。根据您的 index.js 文件,您需要像这样加载您的功能:

aurelia.use.feature('resources`);

假设该功能的 index.js 文件位于 resources 文件夹中。您可能需要将 index.js 文件更改为

export function configure(config) {
  config.globalResources('./from-now', './date-format');
}

并更新您的目录结构,将 from-now.jsdate-format.js 放入 resources 目录中。您不需要这样做,但从组织的角度来看,这是有道理的。更改参数名称只是为了更好地描述参数是什么(FrameworkConfiguration 实例)。

要在 main.js 文件中加载 gooy/aurelia-animator-tinyanimate,您需要从对 plugin 的调用中删除 'resources/index' 参数。 Aurelia 然后会为您正确加载插件。您的 main.js 文件最终应如下所示:

export function configure(aurelia: Aurelia): void {
        aurelia.use
            .standardConfiguration()
            .developmentLogging()
            .feature('resources')
            .plugin('gooy/aurelia-animator-tinyanimate'); 

        aurelia.start().then(function () { return aurelia.setRoot('views/app'); });
}

此外,请注意 main.ts 中不需要 import {Aurelia} from 'aurelia-framework'; 行。