Skip to content

Commit

Permalink
fix: env vars reading for built
Browse files Browse the repository at this point in the history
cherry-pick of other mfe.
this is like a cherrypick of this pr in learning.
https://github.com/nelc/frontend-app-learning/pull/27/files
This is an error generated of the load of paragonTheme plugin.
  • Loading branch information
johanseto committed Apr 26, 2024
1 parent 6cfb197 commit 81e155e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions webpack.prod.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('fs');
const dotenv = require('dotenv');
const path = require('path');
const { createConfig } = require('@edx/frontend-build');

Expand All @@ -10,4 +12,16 @@ config.resolve.modules = [

config.module.rules[0].exclude = /node_modules\/(?!(query-string|split-on-first|strict-uri-encode|@edx))/;

// The configuration is generated using the createConfig method from the frontend-build library,
// this method preloads multiple files to generate the resulting configuration, including webpack.common.config.js,
// https://github.com/nelc/frontend-build/blob/open-release/palm.nelp/config/webpack.common.config.js,
// which includes ParagonWebpackPlugin. This plugin, in turn, retrieves its configuration from the .env.development file
// https://github.com/nelc/frontend-build/blob/open-release/palm.nelp/lib/plugins/paragon-webpack-plugin/ParagonWebpackPlugin.js#L20-L22
// Therefore, regardless of the configuration type, the plugin always utilizes data from .env.development.
// The following code overrides this behavior in order to use the .env file.
const envConfig = dotenv.parse(fs.readFileSync('.env'));
Object.keys(envConfig).forEach(k => {
process.env[k] = envConfig[k];
});

module.exports = config;

0 comments on commit 81e155e

Please sign in to comment.