Skip to content

Commit

Permalink
fix: read .env vars for production built
Browse files Browse the repository at this point in the history
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 Mar 13, 2024
1 parent f57148f commit c9bdcb0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions webpack.prod.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');
const dotenv = require('dotenv');
const { createConfig } = require('@edx/frontend-build');

Check failure on line 3 in webpack.prod.config.js

View workflow job for this annotation

GitHub Actions / tests

Expected 1 empty line after require statement not followed by another require
const config = createConfig('webpack-prod');

// 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 c9bdcb0

Please sign in to comment.