jspm找不到'功能'Aurelia应用程序的插件

jspm cannot find globalResources of a 'feature' plugin for Aurelia app

本文关键字:插件 应用程序 Aurelia jspm 功能 找不到      更新时间:2023-09-26

Aurelia文档描述了如何在http://aurelia.io/docs.html#features

我遇到了一些麻烦,因为jspm或Aurelia似乎正在转换资源路径。我发现,如果用.aurelia.use.feature('./plugins/auth');指定当前路径,则在引导时无法找到calvert-auth/index.js。请求看起来是正确的,但浏览器抛出404错误。我只是通过从.aurelia.use.feature('plugins/auth'); 中删除"./"来解决这个问题

接下来,我在index.s的configure()中向frameworkConfig.globalResources('auth')添加了一个调用。这导致了一个新的404错误,因为请求的是calvert-auth/auth.html,而不是预期的calvert-auth/auth.js

我怀疑问题可能在jspm配置或corejs中,但还无法隔离它。

如何为Aurelia创建和使用内部功能插件?以下是类别:

config.js

...
paths: {
  "*": "dist/*",
  "github:*": "jspm_packages/github/*",
  "npm:*": "jspm_packages/npm/*"
},
...

main.js

import 'bootstrap';
import authConfig from './auth-config';
export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .feature('plugins/calvert-auth', (baseConfig) => {
      baseConfig.configure(authConfig);
    });
  aurelia.start().then(a => a.setRoot());
}

插件/calvert auth/auth.js

export class Auth {
  constructor() {
    console.log('Auth: constructor()');
  }
}

插件/calvert auth/index.js

import {BaseConfig} from './baseConfig';
export function configure(frameworkConfig, configCallback) {
  frameworkConfig.globalResources('./auth');
  let baseConfig = frameworkConfig.container.get(BaseConfig);
  if (configCallback !== undefined && typeof(configCallback) === 'function') {
    configCallback(baseConfig);
  }
}

试试这个:

假设你的代码在上面,并且这个结构:

main.js
plugins/calvert-auth/index.js
plugins/calvert-auth/auth.js

在main.js:中

import 'bootstrap';
import authConfig from './auth-config';
export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .feature('plugins/calvert-auth', (baseConfig) => {
      baseConfig.configure(authConfig);
    });
  aurelia.start().then(a => a.setRoot());
}

在插件/calvert auth/index.js:中

export function configure(frameworkConfig, configCallback) {
  // this assumes you're importing a view model
  frameworkConfig.globalResources('auth');
}

在插件/calvert auth/auth.js:中

import {noView} from 'aurelia-framework';
@noView
export class Auth {
  constructor() {
    console.log('Auth: constructor()');
  }
}