简体   繁体   中英

How to set flags in ember-cli, other than environment?

This is currently possible:

ember build --environment=production

... and I would like to do something like this instead:

ember build --environment=production --baseurl=foo

but config/environment.js only gets passed in the value of environment .

Is it possible to get the value of the other options passed in at the command line too?

You could set environment variables the old fashioned way ( export WHATEVER=wee ) from terminal or as part of a build script, then reference them in your Brocfile.js via node with process.env.WHATEVER . After that, it would be a matter of having broccoli do whatever it is you needed to do with them. You could pre-process files and replace strings, for example.

... just a suggestion. Not sure if that's what you're looking for or not.

It appears that this is not allowed:

Looking in node_modules/ember-cli/lib/commands/build.js , we see:

availableOptions: [
  { name: 'environment', type: String, default: 'development' },
  { name: 'output-path', type: path, default: 'dist/' }
],

... and in node_modules/ember-cli/lib/models/command.js

this.availableOptions.forEach(function(option) {
  knownOpts[option.name] = option.type;
});

... which together mean that any options that are not defined, for each subcommand of ember , get discarded.

You can do foo=bar ember build (however doing ember build foo=bar doesn't work)

And the argument is available via process.env.foo .

To extend upon @ben's answer.

The raw command line arguments are available inside ember-cli-build.js and other files from the

process.argv.[]

So a command like this

ember build staging

you can access via:

process.argv.includes('staging')

see node's documentation for whats available.

https://nodejs.org/docs/latest/api/process.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM