title: Configure build flavors for cordova
body: <p>Hi this question is most likely just a cordova question. I've seen simular questions but never with a satisfactory answer.</p>
  
  <p>What my end goal would be, is a simple way to build multiple Flavors of both an Android, iOS and Windows Phone app.</p>
  
  <p>What my biggest requirements are:</p>
  
  <ul>
  <li>Change the namespace. So the widget attributes in config.xml would preferably be overwritten. Also the name and description would help.</li>
  <li>Generating different icons and splash screens. I'd likely set up directories relevant to the package name I'm using. Putting a high res Splash and Icon in here, using ionic's resources command to generate the correct files.</li>
  <li>Color scheme changes based on target</li>
  <li>Optionally, dynamic configuration.</li>
  </ul>
  
  <p>What I've currently done is added some code in my webpack.config (my ionic project uses webpack). To change sass colours, I could easily add some other options here as well.</p>
  
  <p>This is probably the worst way to implement it but I just needed a working prototype</p>
  
  <pre><code>var flavour = "some.namespace.dir";
  var ENV = "TEST";
  
  for(var i = 0; i &lt; args.length ; i++) {
      if (args[i] == "--env") {
          if (args[i+1]) {
              ENV = args[i+1];
          }
      }
  
      if (args[i] == "--flavour") {
          if (args[i+1]) {
              flavour = args[i+1];
          }
      }
  }
  </code></pre>
  
  <p>So this would check if the node command had any --flavour or --env flag to set these properties. after this I'll load the config in a dumb way.</p>
  
  <pre><code>var config =
      JSON.parse(
          require('fs').readFileSync(
              require('path').resolve(
                  __dirname,
                  'flavours/' + flavour + ".json"),
              'utf8'));
  </code></pre>
  
  <p>Allright so I have a json object, I can put nearly anything in here, so for doing custom styling we can use the sass loader.</p>
  
  <pre><code>sassLoader: {
      includePaths: [
          'node_modules/ionic-angular',
          'node_modules/ionicons/dist/scss'
      ],
      data: "$custom-primary: " + config.colorPrimary + " ; $custom-accent: " + config.colorAccent + " ;"
  },
  </code></pre>
  
  <p>So this actually lets me add variables to the sass build, great!
  as for the configuration:</p>
  
  <pre><code>new DefinePlugin({
     'ENV': JSON.stringify(ENV),
     'appConfig': JSON.stringify(config)
  })
  </code></pre>
  
  <p>So I've got these things which I can use to have the logic inside the app be specific to a flavour.</p>
  
  <p>I'd love to hear how dissapointed people are in my implementation and if they have suggestions to improve any of this.</p>
  
  <p>Also as of now I'm thinking I will need a bash script to change my config.xml and the resources. I can either have a template file in which I replace the namespaces, or I just create config.xml files in my "flavour" folders and copy these in place.</p>
  
  <p>Any suggestions or wtf's people can share? As for now I'll probably go with the config in each directory approach, together with the resources. That way I could just hit a bash file to build compile and sign for any flavour.</p>