Auto-detect production mode, and use the right .js file

This has been tested using "stage"; you should probably also check it with "dist", but I expect it should work.