[Feature Request] Add alternate output option
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 exportShould output to the directoryexport
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?
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 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 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 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 @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?
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 Thanks for taking a look! I've posted an example. And yeah, there's a --target flag. If not provided with the command it
- uses the target in
build.defaultTargetif it's specified, or - the target
webif it exists inbuild.targets, or - a (semi-random) target in
build.targets(so do usedefaultTargetif you want to skip the flag)
https://github.com/aurelia/cli/pull/765