cli icon indicating copy to clipboard operation
cli copied to clipboard

[Feature Request] Add alternate output option

Open CasiOo opened this issue 9 years ago • 8 comments

I'm submitting a feature request

  • Library Version: 0.23.0

Please tell us about your environment:

  • Operating System: Windows 10

  • Language: ESNext

Current behavior: It is currently not possible to change your output directory when running au build.

You are currently unable to change it through editing the build tasks, because the CLI bundler will use the new output path when finding & replacing the script tag src in index.html. It won't be able to update the vendor-bundle src.

https://github.com/aurelia/cli/blob/master/lib/build/bundle.js#L217

Expected/desired behavior: The ability to specify the output directory for a build, depending on the environment.

We tried with the following snippet inserted in the build.js task, but it was unable to update vendor-bundle in the index file.

import {CLIOptions, build} from 'aurelia-cli';
import project from '../aurelia.json';

if (CLIOptions.hasFlag('output')) {
    project.build.targets[0].output = CLIOptions.getFlagValue('output');
}
  • What is the expected behavior? The command au build --env prod --output export Should output to the directory export

I feel like we should look at changing the way CLI updates the path to vendor-bundle. Maybe the setIndexFileConfigTarget part should be a task that the developer can edit themselves?

CasiOo avatar Dec 15 '16 20:12 CasiOo

I'm working on a PR that would in a way solve this. Here's what I currently have: In aurelia.json, the build.targets would change from

    [
      {
        "id": "web",
        "displayName": "Web",
        "output": "scripts",
        "index": "index.html",
        "baseDir": "."
      }
    ]

to

    [
      {
        "id": "default",
        "root": "build",
        "output": "scripts",
        "index": "index.html",
        "baseDir": "."
        ]
      },
      {
        "id": "dev",
        "root": "build/dev"
      },
      {
        "id": "prod",
        "root": "build/prod"
      }
    ]

It wouldn't be a command line argument, but you'd be able to configure it quite easily. Would this work for you? Any comments?

jwx avatar Jun 08 '17 00:06 jwx

@jwx Aren't the targets part meant for building toward multiple target platforms like web, Electron, mobile etc. ? I don't think we're supposed to add a prod and dev target.

CasiOo avatar Jun 26 '17 21:06 CasiOo

@CasiOo If there are ideas behind targetS (as in more than one) I couldn't find anything in the code (which only uses targets[0]). The au build should now however work with anything after --env so it would be possible to build web, cordova or electron with this. (Or even cordova-dev, electron-prod and so on.)

Furthermore, aurelia.json seems to currently only support one platform per project. I think there's more to do if we're to have true multi platform projects. And that might also include a --platform flag for the build command, making it, for example, au build --platform cordova --env dev --watch for multi platform projects.

jwx avatar Jun 26 '17 22:06 jwx

@jwx I would really benefit from a platform option where we have multiple index files depending on the same source.

Is somebody currently busy with this or idea when something like this could possibly be available?

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

@johan-v-r @CasiOo I've added a new PR, https://github.com/aurelia/cli/pull/765, that will implement build targets and I think it will cover your needs. Are you missing anything in it?

jwx avatar Oct 05 '17 12:10 jwx

Thanks @jwx , I have left a comment on your PR, and would really appreciate an example of the project.build.targets structure.
Also I'm assuming that the command to build would now be au build --target foo?

johan-v-r avatar Oct 10 '17 17:10 johan-v-r

@johan-v-r Thanks for taking a look! I've posted an example. And yeah, there's a --target flag. If not provided with the command it

  1. uses the target in build.defaultTarget if it's specified, or
  2. the target web if it exists in build.targets, or
  3. a (semi-random) target in build.targets (so do use defaultTarget if you want to skip the flag)

jwx avatar Oct 10 '17 21:10 jwx

https://github.com/aurelia/cli/pull/765

Alexander-Taran avatar Mar 19 '18 19:03 Alexander-Taran