【问题标题】:Using Aurelia CLI with the new webpack option, how would I add a reference to aurelia-auth将 Aurelia CLI 与新的 webpack 选项一起使用,我将如何添加对 aurelia-auth 的引用
【发布时间】:2017-08-31 02:17:07
【问题描述】:

我使用最新的 aurelia-cli 建立了一个新的 Aurelia 项目。我选择使用 webpack 和 TypeScript。在使用 webpack 将插件添加到项目中时,似乎没有太多的文档方式。我想添加 aurelia-auth。我尝试将它添加到我的 package.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 捆绑和运行应用程序时添加引用的正确方法是什么?

【问题讨论】:

    标签: typescript webpack aurelia aurelia-auth


    【解决方案1】:

    对于 Webpack:

    webpack.config.js 中,plugins 属性中有一个ModulesDependenciesPlugin 条目。在其中添加 aurelia-auth,例如:

    new ModuleDependenciesPlugin({
      'aurelia-testing': [ './compile-spy', './view-spy' ],
      'aurelia-auth': [ './auth-filter' ]
    }),
    

    对于 RequireJS: 您应该将该插件添加到您的 aurelia.jsonbuild.bundles.dependencies 属性中。

    尝试以下方法:

        "dependencies": [
          ...,
          {
            "name": "aurelia-auth",
            "path": "../node_modules/aurelia-auth/dist/amd",
            "main": "aurelia-auth"
          }
        ]
    

    【讨论】:

    • 这适用于默认的 RequireJS 配置,但是当我将模块加载器设置为 Webpack 时,aurelia.json 中没有依赖项部分。我添加了它以查看它是否会起作用,但没有骰子。它仍然给出同样的错误。
    • 对不起,我的错。我用 webpack 解决方案更新了我的帖子。也许这适合你。
    • 想在这里为其他愚蠢的人发表评论 - 您需要确保添加 Aurelia Webpack 插件的 ModuleDependenciesPlugin 部分才能使其正常工作! IE: const { AureliaPlugin, ModuleDependenciesPlugin } = require('aurelia-webpack-plugin');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多