Sign up
Sign in
There is a lot said about orthogonal nature of .env
and how to use dotenv
module, but IMO it does not apply to SPA applications, which are built before they are deployed. The project I currently work on is hosted on Google Cloud Engine and I have to build my Nuxt app before deploying it. It makes sense for me to have multiple .env
files that apply to development
and production
apps that I work with, as I don’t have a dedicated automated CI process for it, where I could have a separate .env
file.
So, here is what you can do.
dotenv
yarn add dotenv
2. Create config.js
Create a module that will load the correct .env
file based on current NODE_ENV
value.
3. Load config.js
in nuxt.config.js
In this example we are using Stripe module and using .env
value based on our current environment.
You could then add additional env
property to your nuxt config to declare env variables used in your public facing components.
4. Create your .env
files
Now for each environment, create a .env file and populate the values. Nuxt run with two NODE_ENV
environments: development
and production
. So, create .env
file for production enviroment, and .env.development
for dev.
I would also encourage you to create a env.example
file and document all the values being used in your app. Since, you wouldn’t want to commit your .env files, having an example file, will make it easier to create .env
files by copy/pasting them on whatever server the build is taking place.
ITNEXT
Full-stack developer, passionate about front-end frameworks, design systems and UX.
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams
4617作文网灵机易起名芭比梦想豪宅游戏下载游戏破解保险起名的起酒店名会展服务有限公司起名宝宝什么时候起名字好呢宝宝起名于2018狗年宝宝起名用什么字好天干地支与周易全国起名大全姓韦起什么名字周易起名字软件给姓岳男宝宝起名手机版造梦西游4破解版起名 缺金缺土如何起个好的宝宝名称根据什么可以给孩子起一个好名字期货黄金周末交易吗洪姓宝宝起名大全男孩粮油商贸起名烤肉拌饭起店名三个人公司怎样起名梦想三国免费内购破解大盘鸡店起名大全孕39周容易饿的原因周公解梦梦见别人打架姓许的怎么起名曹 起名字周易姓名测试梅花打分四柱神煞排盘算命淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男子给前妻转账 现任妻子起诉要回网友建议重庆地铁不准乘客携带菜筐月嫂回应掌掴婴儿是在赶虫子重庆警方辟谣“男子杀人焚尸”国产伟哥去年销售近13亿新的一天从800个哈欠开始男孩疑遭霸凌 家长讨说法被踢出群高中生被打伤下体休学 邯郸通报男子持台球杆殴打2名女店员被抓19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警两大学生合买彩票中奖一人不认账德国打算提及普京时仅用姓名山西省委原副书记商黎光被逮捕武汉大学樱花即将进入盛花期今日春分张家界的山上“长”满了韩国人?特朗普谈“凯特王妃P图照”王树国3次鞠躬告别西交大师生白宫:哈马斯三号人物被杀代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了房客欠租失踪 房东直发愁倪萍分享减重40斤方法“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火手机成瘾是影响睡眠质量重要因素考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼网友洛杉矶偶遇贾玲呼北高速交通事故已致14人死亡西双版纳热带植物园回应蜉蝣大爆发男孩8年未见母亲被告知被遗忘张立群任西安交通大学校长恒大被罚41.75亿到底怎么缴沈阳一轿车冲入人行道致3死2伤奥运男篮美国塞尔维亚同组周杰伦一审败诉网易国标起草人:淀粉肠是低配版火腿肠外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万杨倩无缘巴黎奥运男子被猫抓伤后确诊“猫抓病”春分“立蛋”成功率更高?记者:伊万改变了国足氛围奥巴马现身唐宁街 黑色着装引猜测