xian-ncc-da-client/EnvParse.js

20 lines
532 B
JavaScript
Raw Permalink Normal View History

2023-10-20 10:58:31 +08:00
const DotEnv = require('dotenv');
2023-10-16 14:01:38 +08:00
module.exports = function () {
2023-10-17 11:09:53 +08:00
let script = process.env.npm_lifecycle_script;
2023-10-20 10:58:31 +08:00
let name = 'dev';
if (script) {
// quasar启动没有这个
script = script.substring(script.indexOf('NODE_ENV=') + 'NODE_ENV='.length);
name = script.substring(0, script.indexOf('&'));
} else {
if (process.env.NODE_ENV == 'production') {
name = 'prod';
}
}
2023-10-17 11:09:53 +08:00
console.log(name);
2023-10-20 10:58:31 +08:00
name = '.env.' + name;
let parsedEnv = DotEnv.config({ path: name }).parsed;
return parsedEnv;
};