我使用最新的Aurelia cli设置了一个新的Aurelia项目。我选择使用webpack和TypeScript。在使用webpack时,在项目中添加插件时,似乎没有太多文档。我想在中添加aurelia auth。我试着将它添加到我的包.json:中的aurelia部分
"aurelia": {
"build": {
"resources": [
"aurelia-auth"
]
}
}
然后使用它:
aurelia.use
.standardConfiguration()
.feature(PLATFORM.moduleName('resources/index'))
.plugin(PLATFORM.moduleName('aurelia-auth'), (baseConfig)=>{
baseConfig.configure({});
});
但似乎并不是所有的东西都成功了:
未处理的拒绝错误:找不到ID为的模块:aurelia auth/auth过滤器
使用Aurelia CLI和webpack捆绑和运行应用程序时,添加引用的正确方法是什么?
对于Webpack:
在webpack.config.js
中,plugins
属性中有一个ModulesDependenciesPlugin
条目。在其中添加aurelia auth,例如:
new ModuleDependenciesPlugin({
'aurelia-testing': [ './compile-spy', './view-spy' ],
'aurelia-auth': [ './auth-filter' ]
}),
对于RequireJS:您应该将插件添加到aurelia.json
的build.bundles.dependencies
属性中。
尝试以下操作:
"dependencies": [
...,
{
"name": "aurelia-auth",
"path": "../node_modules/aurelia-auth/dist/amd",
"main": "aurelia-auth"
}
]