m0dch3n / vue-cli-plugin-cordova

Vue Cli 3 Cordova Plugin
MIT License
417 stars 63 forks source link

In prod script: process.env.NODE_ENV === "production" returns false #17

Closed eladcandroid closed 6 years ago

m0dch3n commented 6 years ago

After investigating into this, I found the problem, it comes from loadEnv in vue cli Service...

This method checks if there are .env files like .env.cordova-build-android, and if not, it sets process.env.NODE_ENV to development by default

As loadEnv is first called with i.e. 'cordova-build-android', it is set to development already. Afterwards, when I call build, loadEnv, will not override process.env.NODE_ENV anymore, because it's not null.

So one solution would be, to create .env.cordova-build-android, and put there NODE_ENV=production, like in their staging example

Another solution, would be maybe, that I unset process.env.NODE_ENV before I run build, however this would unset any setting from the .env.cordova-build-android file.

I would need to test this more, I think, if the .env.cordova-build-platform doesn't exist, there's no problem to unset it, or if it exists, I need to check, if NODE_ENV is set, in this file...

However I personally don't like this second solution much, because it's more a work around the problem from loadEnv...

m0dch3n commented 6 years ago

PS: For my commands I need to have different modes, otherwise the part with process.env.CORDOVA_PLATFORM, and the JSMiddleware are not working...

m0dch3n commented 6 years ago

I created a feature request for the cli, because I think, this is the best solution IMO.

In the meantime, you can add the specific .env.cordova-build-platform files...

eladcandroid commented 6 years ago

Great!! Thanks a lot!

4lyn commented 6 years ago

FWI it also allows you to build using different mode vue-cli-service cordova-build-android --mode staging That was not possible with the previous version