@@ -106,12 +106,30 @@ module.exports = (api, projectOptions) => {
106106 // get the --env command line options and put them in the env variable
107107 const [ , , ...processArgs ] = process . argv ;
108108 flags = [ ...processArgs ] . filter ( ( f ) => f . startsWith ( '--env.' ) ) . map ( ( f ) => f . substring ( 6 ) ) ;
109+
110+ // in the rare event that tns and vue-cli get things mixed up and try and load the production
111+ // environment and development environment at the same time, we will default to loading
112+ // the development environment. you will generally see this when using something like
113+ // fastlane and having it do a 'tns prepare' as you are prepping to package and upload
114+ // your app to the app store. For internal testing you may want to package a development
115+ // version of the app, but `tns prepare` will try and load the production environmental variables
116+ if ( flags . includes ( 'development' ) && flags . includes ( 'production' ) ) {
117+ const index = flags . findIndex ( ( obj ) => obj === 'production' )
118+ if ( index > - 1 ) {
119+ flags . splice ( index , 1 ) ;
120+ }
121+ }
122+
109123 // console.log('tns cli - flags - ', flags);
110124
111125 // take advantage of the vue cli api to load the --env items into process.env.
112126 // we are filtering out the items, by catching the '=' sign, brought in from nsconfig.json as those don't need loaded into process.env
113- // we are also filtering out 'sourceMap' which will appear with 'tns debug'
114- api . service . loadEnv ( flags . filter ( ( o ) => ! o . includes ( '=' ) && ! o . includes ( 'sourceMap' ) && ! o . includes ( 'hmr' ) ) . join ( '.' ) ) ;
127+ // we are also filtering out 'sourceMap' which will appear with 'tns debug' as well as 'hmr' and 'uglify'
128+ // the goal here is to figure out exactly what environmental variables to load
129+ const mode = flags . filter ( ( o ) => ! o . includes ( '=' ) && ! o . includes ( 'sourceMap' ) && ! o . includes ( 'hmr' ) && ! o . includes ( 'uglify' ) ) . join ( '.' ) ;
130+ // console.log('loadEnv - ', mode);
131+ api . service . loadEnv ( mode ) ;
132+
115133 }
116134
117135 // setup the traditional {N} webpack 'env' variable
0 commit comments