Multiple Aurelia Instances - Aurelia Webpack Plugin - aureliaApp option - “module not found”

风格不统一 提交于 2019-12-24 10:56:35

问题


I am composing my web app as a number of Aurelia "feature" apps - although I'm not using Aurelia features as such. Consequently in my html markup I have two entry points pointing to different apps:

<!-- Top Navigation Bar --> 
<div aurelia-app="topnav"></div>

<!-- Main App--> 
<div aurelia-app="main"></div>

I am using webpack and everything works perfectly using the single "main" app. Webpack generates a JS file "main.bundle.js" which I include in the src tag.

Things are not so straightforward when I added the "topnav" app. In webpack I tell the plugin to use a different aureliaApp name:

 new AureliaPlugin({ aureliaApp: "topnav"}),

and, as you can see my HTML entrypoint also calls "topnav". Webpack generates a JS file "topnav.bundle.js" which I also include. I have a file called "topnav.ts" which contains the aurelia Cionfigure function which ends:

     aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName("nav")));

And a pair of files "nav.ts", "nav.html" which constitute my viewmodel and view.

When I run the app aurelia loads and the "nav" module code executes. But I then get an error - see below.

The module which it reports that it cannot find is the one entered into the HTML markup.

Should this work? Have I missed something?

I should add, everything seems to work. I can create and update properties in the viewmodel and these are bound to the view. It's just that this error is thrown.


回答1:


You are doing nothing wrong, just unsupported scenario. Per official doc-wiki: https://github.com/aurelia/webpack-plugin/wiki/AureliaPlugin-options#aureliaapp

You can have only 1 auto entry module with aureliaApp configuration. To solve this, you just need to add PLATFORM.moduleName('topnav') to your main.ts (and put it on root level)

Another way to do is to bootstrap manually:

// in your index.ts
import { bootstrap } from 'aurelia-bootstrapper';

// bootstrap top nav application, with one instance of Aurelia
bootstrap(aurelia => {
  // do your configuration
  aurelia
    .start()
    .then(() => aurelia.setRoot(
      PLATFORM.moduleName('topnav'),
      document.querySelector('#topnav')
    );
});

// bootstrap main application, with another instance of Aurelia
bootstrap(aurelia => {
  // aurelia.use.standardConfiguration();
  // ...
  aurelia
    .start()
    .then(() => aurelia.setRoot(
      PLATFORM.moduleName('app'),
      document.querySelector('app')
    )
});


来源:https://stackoverflow.com/questions/54842870/multiple-aurelia-instances-aurelia-webpack-plugin-aureliaapp-option-modul

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!