Javascript jspm找不到';功能';Aurelia应用程序插件
Aurelia文档描述了如何在 我遇到了一些麻烦,因为jspm或Aurelia似乎正在转换到资源的路径。我发现如果我用Javascript jspm找不到';功能';Aurelia应用程序插件,javascript,aurelia,jspm,Javascript,Aurelia,Jspm,Aurelia文档描述了如何在 我遇到了一些麻烦,因为jspm或Aurelia似乎正在转换到资源的路径。我发现如果我用.aurelia.use.feature('./plugins/auth')指定当前路径启动时找不到calvert auth/index.js。请求看起来正确,但浏览器抛出404错误。我只需从.aurelia.use.feature('plugins/auth')中删除“/”,就解决了这个问题 接下来,我在index.s的configure()中添加了对frameworkConf
.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
export class Auth {
constructor() {
console.log('Auth: constructor()');
}
}
我怀疑问题可能出在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());
}
在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()');
}
}
嗨@shanonvl,我添加了更多细节,包括我的main.js。是的,目录结构是相同的。我注意到的唯一区别是我有globalResources('./auth'),而你的显示globalResources('auth')。我试过了,结果是一样的。请求错误是:未处理的承诺拒绝错误:XHR错误(404未找到)加载您可以发布config.js的路径部分吗?另外,main.js应该是:。developmentLogging().feature('plugins/calvert auth',(baseConfig)=>{..(不要重做aurelia.use)添加了config.js中的代码段,并更正了aurelia.use链。问题仍然存在。更新了上面的代码。显然,globalResources假定您正在导入视图模型,从而导入auth.html请求。您可以使用@noView decorator告诉它没有视图。