Question: how to invoke some script during ionic tasks #335
Comments
For the command flag/argument you can use yargs Its an amazing library. In your const yargs = require("yargs");
const argv = yargs(JSON.parse(process.env.npm_config_argv).original)
.default("release", false)
.argv;
if (argv.release) {
// code here
} Also you can try the below "scripts": {
"prebuild": "node ./scripts/generate-config.js ",
"build": "./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build"
}, |
Unfortunately i couldn't make it work. const yargs = require("yargs");
const argv = yargs(JSON.parse(process.env.npm_config_argv).original)
.default("release", false)
.argv; And "scripts": {
"ionic:serve": "node ./scripts/generate-config.js && ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js serve"
}, When i try to reach ionic serve --release
ionic serve --release true
ionic serve --release=true
ionic serve --release="true" |
@aszmyd can you try to use this |
@alan-agius4 nope, |
+1 I think this has to do with an issue I opened in the ionic-cli repository, I got a response from the ionic team there so you can view their opinion on the matter. This is the issue: ionic-team/ionic-cli#1757 |
@NoelDeMartin yes it seems to be somehow related. <hook type="before_build" src="scripts/some-action.js" /> And inside
The |
@aszmyd Yes that's also what I did at the beginning, but it was a problem for me since I wanted to execute a script both in build and serve commands. Since serve command doesn't call any hooks, this created a situation where it was impossible not to duplicate code. At the moment I have created my own wrapper for the ionic cli and I call all my scripts before passing the functionality to ionic, but I understand this is not necessary in all projects, cordova hooks and app scripts should work in most situations. |
We probably aren't going to get to this for awhile. Thanks, |
I ran into this a couple of days ago and I'm still looking for a work-around. I have a custom webpack config and passing arguments to I could use environment variables, but setting these cross-platform is not fun. Did anyone come up with a solution? PoC repository: https://github.com/pbowyer/ionic-cascading-config |
I have a question - is it possible to somehow nicely invoke some node script before ionic
build
andserve
tasks? I want to generate config files based on environment and platform (android, ios). Earlier i've just made a gulp task likeconfig
and inject it into gulp tasks. Here we havepackage.json
scripts:I wanted to modify it like that:
and it works but the issue is that
generate-config.js
script does not have access to initial command line arguments. I.e. when i runionic build android --release
i cannot figure out that therelease
option has been used. The same with any other initial arguments.Is there DRY and nice way to achieve that?
The text was updated successfully, but these errors were encountered: