Is this an expected behavior difference between the two?
Seems serve cannot handle environment being set in configuration files and defaults always to development.
Is this a bug?
normally you would set the env via the command line - like jekyll serve JEKYLL_ENV=production - at least I think that is correct. I saw an example with the env stuff before the command.
I think for serve the default is always development and for build it is production.
I did not see anything saying you can set it inside the config file so I think what you are doing isn’t even being shown in the site folder, try changing the config env you have to something random and I bet you get the same thing as you are now.
If you could set it via the config file I think it would be via JEKYLL_ENV but setting it in the config file seems like a bad idea as how would that work? that would seem to defeat the purpose of an env variable.
Jekyll gives you a lot of flexibility to customize how it builds your site. These options can either be specified in a _config.yml or _config.toml file placed in your site’s root directory, or can be specified as flags for the jekyll executable in the terminal. Configuration | Jekyll • Simple, blog-aware, static sites
So all config options, including jekyll.environment, I would expect as a valid entry in the configuration files.
No syntax errors, and with build that works pretty well (does not fall back to a default production)
However, serve is different, and my question is around that.
I would prefer configuration files over environment variables because with them it is easy to manage environments with different configs easily. And if I have multiple files already, then it would also make sense to include the environment config itself into them.