From dcacaccccc77add195458a552f0b061d381e29ef Mon Sep 17 00:00:00 2001 From: Adam Brauer <400763+ambrauer@users.noreply.github.com> Date: Thu, 20 Jan 2022 14:17:12 -0600 Subject: [PATCH] [RAV] Bring environment variable support to config generation (part 2): fix Angular config generation and add polyfill for process.env support --- .../src/templates/angular/scripts/generate-config.ts | 4 ++-- .../src/templates/angular/src/polyfills.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts index 9db54bfcc5..8d2591ecd1 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/generate-config.ts @@ -45,7 +45,7 @@ export function generateConfig(configOverrides?: { [key: string]: unknown }, out let configText = `/* eslint-disable */ // Do not edit this file, it is auto-generated at build time! // See scripts/bootstrap.ts to modify the generation of this file. -const config = {};\n`; +const config: { [key: string]: string } = {};\n`; // Set base configuration values, allowing override with environment variables Object.keys(config).forEach((prop) => { @@ -57,7 +57,7 @@ const config = {};\n`; computedConfig[prop] };\n`; }); - configText += `module.exports = config;`; + configText += `export const environment = config;`; const configPath = path.resolve(outputPath); console.log(`Writing runtime config to ${configPath}`); diff --git a/packages/create-sitecore-jss/src/templates/angular/src/polyfills.ts b/packages/create-sitecore-jss/src/templates/angular/src/polyfills.ts index 4479cf8c4d..b429ddc24b 100644 --- a/packages/create-sitecore-jss/src/templates/angular/src/polyfills.ts +++ b/packages/create-sitecore-jss/src/templates/angular/src/polyfills.ts @@ -46,6 +46,9 @@ import 'core-js/es/reflect'; **/ // import 'web-animations-js'; // Run `npm install --save web-animations-js`. +/** Polyfill for node.js process **/ +(window as any).process = { env: { DEBUG: undefined }, }; + /***************************************************************************************************