【发布时间】:2020-05-20 04:02:10
【问题描述】:
以下是我的gulpfile.js:
const nodemon = require('nodemon')
const server = nodemon({
script: './src/index.js',
ext: 'hbs json js css',
require: 'dotenv/config',
dotenv_config_path: './config/.env',
stdout: false // without this line the stdout event won't fire
})
我希望在 package.json 文件中复制与 dev 脚本完全相同的行为:
"scripts": {
"test": "jest --watch",
"dev": "nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css",
"debug": "nodemon --inspect -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css"
},
出于某种原因,gulp 似乎没有注册.env 文件中定义的环境变量。虽然下面的行在使用npm run dev 运行时工作得很好:
nodemon -r dotenv/config ./src/index.js dotenv_config_path=./config/.env -e js,hbs,json,css
【问题讨论】:
-
dotenv_config_path的值中应该有空格吗? -
不,这不应该是复制/粘贴问题
标签: javascript node.js gulp dotenv