If .env is not defined use sane defaults from .env.example
This commit is contained in:
		| @@ -1,5 +0,0 @@ | |||||||
| { |  | ||||||
|     "SEASONED_URL": "http://localhost:31459/api/", |  | ||||||
|     "ELASTIC_URL": "http://localhost:9200", |  | ||||||
|     "ELASTIC_INDEX": "shows,movies" |  | ||||||
| } |  | ||||||
| @@ -5,21 +5,21 @@ const HTMLWebpackPlugin = require("html-webpack-plugin"); | |||||||
| const { VueLoaderPlugin } = require("vue-loader"); | const { VueLoaderPlugin } = require("vue-loader"); | ||||||
| const TerserPlugin = require("terser-webpack-plugin"); | const TerserPlugin = require("terser-webpack-plugin"); | ||||||
| const dotenv = require("dotenv").config({ path: "./.env" }); | const dotenv = require("dotenv").config({ path: "./.env" }); | ||||||
|  | const dotenvExample = require("dotenv").config({ path: "./.env.example" }); | ||||||
|  |  | ||||||
| const sourcePath = path.resolve(__dirname, "src"); | const sourcePath = path.resolve(__dirname, "src"); | ||||||
| const indexFile = path.join(sourcePath, "index.html"); | const indexFile = path.join(sourcePath, "index.html"); | ||||||
| const javascriptEntry = path.join(sourcePath, "main.ts"); | const javascriptEntry = path.join(sourcePath, "main.ts"); | ||||||
| const publicPath = path.resolve(__dirname, "public"); | const publicPath = path.resolve(__dirname, "public"); | ||||||
| const isProd = process.env.NODE_ENV === "production"; | const isProd = process.env.NODE_ENV === "production"; | ||||||
|  | const variables = dotenv.parsed || dotenvExample.parsed; | ||||||
|  |  | ||||||
| // Merge inn all process.env values that match dotenv keys | // Merge inn all process.env values that match dotenv keys | ||||||
| if (dotenv.parsed) { |  | ||||||
| Object.keys(process.env).forEach(key => { | Object.keys(process.env).forEach(key => { | ||||||
|     if (key in dotenv.parsed) { |   if (key in variables) { | ||||||
|       dotenv.parsed[key] = process.env[key]; |     variables[key] = process.env[key]; | ||||||
|   } |   } | ||||||
| }); | }); | ||||||
| } |  | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|   mode: process.env.NODE_ENV, |   mode: process.env.NODE_ENV, | ||||||
| @@ -79,7 +79,7 @@ module.exports = { | |||||||
|       minify: isProd |       minify: isProd | ||||||
|     }), |     }), | ||||||
|     new webpack.DefinePlugin({ |     new webpack.DefinePlugin({ | ||||||
|       "process.env": JSON.stringify(dotenv.parsed) |       "process.env": JSON.stringify(variables) | ||||||
|     }) |     }) | ||||||
|   ], |   ], | ||||||
|   resolve: { |   resolve: { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user