Skip to content

Commit 2683bd9

Browse files
author
PatrickSachs
committed
Allow usage without HTTPS
1 parent afbc13f commit 2683bd9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

webpack.config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const fs = require('fs');
23
const dotenv = require("dotenv");
34
const webpack = require('webpack');
45
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
@@ -8,12 +9,17 @@ const CleanPlugin = require("clean-webpack-plugin");
89
const WorkboxPlugin = require("workbox-webpack-plugin");
910

1011
const isProduction = process.env.NODE_ENV === "production";
12+
process.env.NODE_ENV = isProduction ? "production" : "development";
1113

1214
dotenv.config({ path: ".env.local" });
1315
dotenv.config({ path: isProduction ? ".env.prod" : ".env.dev" });
1416
dotenv.config({ path: ".env" });
1517

16-
console.log("Enviroment variables are:", process.env);
18+
console.log("Enviroment variables are:", {
19+
NODE_ENV: process.env.NODE_ENV,
20+
SERVICE_WORKER: process.env.SERVICE_WORKER,
21+
BROWSERSYNC: process.env.BROWSERSYNC
22+
});
1723

1824
// ===============================================
1925
// MISC SETTINGS
@@ -35,13 +41,17 @@ plugins.push(new webpack.DefinePlugin({
3541
}));
3642
plugins.push(new CopyPlugin(["index.html", "manifest.json", { from: "assets", to: "assets" }]));
3743
if (process.env.BROWSERSYNC === "true") {
44+
const hasCerts = fs.existsSync("ssl/key.pem") && fs.existsSync("ssl/cert.pem");
45+
if (!hasCerts) {
46+
console.log("No SSL Key/Certificate found in /ssl, serving over HTTP.");
47+
}
3848
plugins.push(new BrowserSyncPlugin({
3949
host: process.env.IP || 'localhost',
4050
port: process.env.PORT || 3000,
4151
server: {
4252
baseDir: ['./dist']
4353
},
44-
https: {
54+
https: hasCerts && {
4555
key: "ssl/key.pem",
4656
cert: "ssl/cert.pem"
4757
},

0 commit comments

Comments
 (0)