Aurelia docs描述了如何在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());
}
插件/卡尔弗特-AUTH / auth.js
export class Auth {
constructor() {
console.log('Auth: constructor()');
}
}
插件/卡尔弗特-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);
}
}
答案 0 :(得分:2)
试试这个:
假设您的代码如上,以及此结构:
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());
}
在plugins / calvert-auth / index.js中:
export function configure(frameworkConfig, configCallback) {
// this assumes you're importing a view model
frameworkConfig.globalResources('auth');
}
在plugins / calvert-auth / auth.js中:
import {noView} from 'aurelia-framework';
@noView
export class Auth {
constructor() {
console.log('Auth: constructor()');
}
}