Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring aurelia cli to serve app-bundle from a subfolder

Tags:

aurelia

How can I configure aurelia cli to allow the app to be loaded from a subfolder (a mvc controller vith a view)?

In /MyController/MyView I have the following code

<div aurelia-app="main" data-module="app2">
     <script src="/scripts/vendor-bundle.js" data-main="aurelia-bootstrapper"></script>
</div>

I got an 404 when the loader then tries to load the app-bundle from /MyController/MyView/scripts/app-bundle.js but it actual location is /scripts/app-bundle.js

Thanks for any help

Larsi

Motivation for question: I'm using Aurelia in an existing asp.net mvc 5 website. We plan to develop new pages as small aurelia apps (one aurelia app per mvc view). We plan on reusing the same bundles on all views (just setting "aurelia.setRoot('nameofapp')" to launch the correct app). This seems to work great when launching at '/' but when lanched from '/MyController/MyView' we need to modify the location the app-bundles are loaded from - and this is what this question is about.

like image 675
Larsi Avatar asked Mar 12 '23 13:03

Larsi


2 Answers

Two things needed to be done:

  • Set the ´build.targets.baseUrl: '../scripts'´ in ´aurelia.json´
  • Use "features" as Matthew suggested.

I figured someone else might need this setup, so I created a repository here: https://github.com/larserikfinholt/aurelia-subfolder

Larsi

like image 151
Larsi Avatar answered Apr 08 '23 16:04

Larsi


Use "features"

In your main.js aurelia bootstrap file, you can write this:

main.js

configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .feature('my-app');
}

This will instruct aurelia to load my-app/index.js as a plugin, exposing the aurelia object to a configure() function, just like in the main.js file. You can do all kinds of fun stuff there, including setting a root view model.

my-app/index.js

configure(aurelia) {
  aurelia.start().then(() => aurelia.setRoot('my-app/app.js'));
}
like image 27
Matthew James Davis Avatar answered Apr 08 '23 16:04

Matthew James Davis