cli icon indicating copy to clipboard operation
cli copied to clipboard

[feature requests] Multiple bundles/targets & platforms

Open diegohb opened this issue 6 years ago • 14 comments

I've been trying to figure out how to support multi-spa and leverage build targets and platform in aurelia.json to support a more sophisticated build setup.

attempts:

  1. just standard splitting bundles to break off dependencies (each SPA may have different 3rd-party vendor libraries): https://github.com/diegohb/samples-aurelia-vanilla_cli/tree/master-task017 --this broke the karma tests but otherwise worked.
  2. tried to trick the au bundler to update a razor partial that each razor view references so that both root container SPA pages get the bundler rewrite: https://github.com/diegohb/samples-aurelia-vanilla_cli/tree/master-task018
  3. Now i'm trying to specify SPA-specific bundles and hopefully share the common aurelia & systemjs bundle in both..

The requests:

  1. ability to specify array of strings to build.targets[x].index . eg ["index1.html", "index2.html"]

  2. change updateIndexForConfig() method to work against any type of file, just look for

  3. change build.loader.configTarget property to reference build.targets.id to load it's .index property. This will help avoid having an additional place to change the value of index page to be updated.

  4. add property "buildTarget" to bundle object that works like dependencies[x].env property (can specify multiple target concatenated with ampersand).

  5. add property "platform" to buildTarget to specify what targets are meant for which platforms and then allow parameter "platform". eg. au build --platform "netcore2.0" or "electron" etc..

I wonder if anyone can provide links to source file(s) related to each one of these requests ? I'd love to look at helping out with some.. maybe the first one for starters.. 😃

diegohb avatar Aug 25 '17 16:08 diegohb

i see it's related to https://github.com/aurelia/cli/issues/442

diegohb avatar Aug 25 '17 16:08 diegohb

I'd love to know why this isn't working as expected to get a better understanding of the internals of the cli and current limitations .. https://github.com/diegohb/samples-aurelia-vanilla_cli/commit/20e557b5acb73e04a7f63d915494da27125cf41b 🆘

diegohb avatar Aug 25 '17 19:08 diegohb

@diegohb i'd like to help you debug but i''m a bit behind on all my other work. If you can wait until next weekend I can help you out

JeroenVinke avatar Aug 25 '17 20:08 JeroenVinke

@JeroenVinke - thanks a lot! 👍 👍 👍

diegohb avatar Aug 25 '17 21:08 diegohb

Adding the following code to the top of my build.js file I can specify au build --target mobile

import project from '../aurelia.json';

let target = "web";
if (CLIOptions.hasFlag("target")) {
  target = CLIOptions.getFlagValue("target")
}

let targetIndex = project.build.targets.findIndex(x => x.id === target);
if (targetIndex < 0) targetIndex = 0;
project.build.targets[0] = project.build.targets[targetIndex];

This is only as a work-around for now until we can get a better solution.

johan-v-r avatar Aug 28 '17 17:08 johan-v-r

@johan-v-r - thanks! that's a great add.. i tried to pull down code also and was going to implement request 1 (multiple index files to update) but I couldn't get my environment setup right.. running karma on cli project causes spec test failures.. hesitant to code without having a good test baseline to start from.

diegohb avatar Aug 28 '17 18:08 diegohb

I found the code that updates the index page and it does not actually care about what kind of file it's pointed to.. so my request number 2 above is unnecessary.
https://github.com/aurelia/cli/blob/aab947791010d714e7a98ad1438ca152ba0ceddf/lib/build/bundle.js#L334

I can't really find any documentation or code related to platform.index property at the top of the aurelia.json file - doesn't seem to be used?

diegohb avatar Aug 28 '17 18:08 diegohb

That's used to replace the reference to the vendor bundle when revisions are used, so a user doesn't have to manually update the links with the generated vendor bundle hash. Should be documented somewhere in the CLI docs...

AStoker avatar Aug 28 '17 20:08 AStoker

@AStoker - I don't think Platform.Index (at the top of the aurelia.json) is used for that.. you mean targets[x].Index - that is used for that.

either way, I've managed to get the revision update to work against an MVC partial so that way I can have multiple SPAs refer to the same bundle revision and sitll leverage CLI auto-update for that - https://github.com/diegohb/samples-aurelia-vanilla_cli/compare/master-task018

diegohb avatar Aug 29 '17 19:08 diegohb

You're correct, my mistake :)

AStoker avatar Aug 29 '17 19:08 AStoker

@diegohb I've added a PR, https://github.com/aurelia/cli/pull/765, that will implement build targets. I think it will cover some of your needs, but not all of them. Could you take a look and let me know what's missing that you need?

jwx avatar Oct 05 '17 12:10 jwx

@jwx thanks a lot! Item 2 can be ignored because it already works that way, index file can be any type of file as long as regex matches. Item 3 is all that's left but maybe you can re-evaluate if it's useful. i think it was just a convenience enhancement. i'm ok if you close this issue.

diegohb avatar Oct 05 '17 14:10 diegohb

question - none of this new build stuff is included in 0.32.0 right ?

diegohb avatar Oct 24 '17 16:10 diegohb

Correct, it's planned for the next one (0.33.0)

JeroenVinke avatar Oct 24 '17 16:10 JeroenVinke