11const path = require ( 'path' ) ;
2+ const fs = require ( 'fs' ) ;
23const dotenv = require ( "dotenv" ) ;
34const webpack = require ( 'webpack' ) ;
45const BrowserSyncPlugin = require ( 'browser-sync-webpack-plugin' ) ;
@@ -8,12 +9,17 @@ const CleanPlugin = require("clean-webpack-plugin");
89const WorkboxPlugin = require ( "workbox-webpack-plugin" ) ;
910
1011const isProduction = process . env . NODE_ENV === "production" ;
12+ process . env . NODE_ENV = isProduction ? "production" : "development" ;
1113
1214dotenv . config ( { path : ".env.local" } ) ;
1315dotenv . config ( { path : isProduction ? ".env.prod" : ".env.dev" } ) ;
1416dotenv . 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} ) ) ;
3642plugins . push ( new CopyPlugin ( [ "index.html" , "manifest.json" , { from : "assets" , to : "assets" } ] ) ) ;
3743if ( 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