1

I set up a new Aurelia project using the latest aurelia-cli. I chose to use webpack and TypeScript. It appears there is not much in the way of documentation when it comes to adding plugins into a project when using webpack. I would like to add aurelia-auth in. I tried adding it to an aurelia section in my package.json:

  "aurelia": {
    "build": {
      "resources": [
        "aurelia-auth"
      ]
    }
  }

Then using it:

aurelia.use
  .standardConfiguration()
  .feature(PLATFORM.moduleName('resources/index'))
  .plugin(PLATFORM.moduleName('aurelia-auth'), (baseConfig)=>{
     baseConfig.configure({});
  });

But it does not appear that everything made it in:

Unhandled rejection Error: Unable to find module with ID: aurelia-auth/auth-filter

What is the correct way to add references when using Aurelia CLI and webpack to bundle and run an application?

Jereme
  • 1,445
  • 1
  • 16
  • 32

1 Answers1

4

For Webpack:

In the webpack.config.js, there is a ModulesDependenciesPlugin entry within the plugins property. Add aurelia-auth in there, e.g.:

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

For RequireJS: You should add the plugin to your aurelia.json's build.bundles.dependencies property.

Try the following:

    "dependencies": [
      ...,
      {
        "name": "aurelia-auth",
        "path": "../node_modules/aurelia-auth/dist/amd",
        "main": "aurelia-auth"
      }
    ]
Marc Scheib
  • 1,963
  • 1
  • 24
  • 29
  • That works for the default RequireJS configuration, but when I set the module loader to Webpack there is no dependencies section in aurelia.json. I added it in to see if it would work, but no dice. It still gives the same error. – Jereme Aug 30 '17 at 17:05
  • Sorry, my fault. I updated my post with a webpack solution. Perhaps this makes it for you. – Marc Scheib Aug 30 '17 at 18:17
  • Wanted to comment here for anyone else here who is stupid - You'll need to be sure to add the ModuleDependenciesPlugin portion of the Aurelia Webpack plugin in order for this to work! I.E: const { AureliaPlugin, ModuleDependenciesPlugin } = require('aurelia-webpack-plugin'); – Ryanman Nov 07 '17 at 21:44