diff --git a/EnvParse.js b/EnvParse.js index 2925aa1..52e047f 100644 --- a/EnvParse.js +++ b/EnvParse.js @@ -1,12 +1,19 @@ - -const DotEnv = require('dotenv') +const DotEnv = require('dotenv'); module.exports = function () { let script = process.env.npm_lifecycle_script; - script = script.substring(script.indexOf("NODE_ENV=") + "NODE_ENV=".length); - let name = script.substring(0,script.indexOf("&")) + 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'; + } + } console.log(name); - name = ".env." + name - let parsedEnv = DotEnv.config({ path: name }).parsed - return parsedEnv -} + name = '.env.' + name; + let parsedEnv = DotEnv.config({ path: name }).parsed; + return parsedEnv; +};