Skip to content

Commit

Permalink
fix: add back in the webpack.prod.config as patch-package will only w…
Browse files Browse the repository at this point in the history
…ork in development

* since frontend-build is a devdependency, post-package will not include its patches in prod
  • Loading branch information
jsnwesson committed Feb 9, 2024
1 parent a4689a5 commit 2ad54d9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 41 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"i18n_extract": "fedx-scripts formatjs extract",
"lint": "fedx-scripts eslint --ext .js --ext .jsx .",
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx .",
"postinstall": "patch-package",
"serve": "fedx-scripts serve",
"snapshot": "fedx-scripts jest --updateSnapshot",
"start": "fedx-scripts webpack-dev-server --progress",
Expand Down
50 changes: 9 additions & 41 deletions patches/@edx+frontend-build+13.0.14.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
diff --git a/node_modules/@edx/frontend-build/config/jest.config.js b/node_modules/@edx/frontend-build/config/jest.config.js
index ae08b70..a198be1 100644
index ae08b70..2c8c0fa 100644
--- a/node_modules/@edx/frontend-build/config/jest.config.js
+++ b/node_modules/@edx/frontend-build/config/jest.config.js
@@ -4,11 +4,14 @@ const fs = require('fs');
@@ -3,12 +3,16 @@ const fs = require('fs');

const presets = require('../lib/presets');

+console.log('If you are expecting to use an env.config.jsx config, make sure to run `npm run postinstall` first!')
let envConfigPath = path.resolve(__dirname, './jest/fallback.env.config.js');
-const appEnvConfigPath = path.resolve(process.cwd(), './env.config.js');
+const appEnvConfigPathJs = path.resolve(process.cwd(), './env.config.js');
+const appEnvConfigPathJsx = path.resolve(process.cwd(), './env.config.jsx');

-if (fs.existsSync(appEnvConfigPath)) {
- envConfigPath = appEnvConfigPath;
-}
Expand All @@ -22,7 +24,7 @@ index ae08b70..a198be1 100644
module.exports = {
testURL: 'http://localhost/',
diff --git a/node_modules/@edx/frontend-build/config/webpack.dev.config.js b/node_modules/@edx/frontend-build/config/webpack.dev.config.js
index 5ce7716..fe9888e 100644
index 5ce7716..6828971 100644
--- a/node_modules/@edx/frontend-build/config/webpack.dev.config.js
+++ b/node_modules/@edx/frontend-build/config/webpack.dev.config.js
@@ -7,6 +7,7 @@ const Dotenv = require('dotenv-webpack');
Expand All @@ -33,10 +35,11 @@ index 5ce7716..fe9888e 100644
const PostCssAutoprefixerPlugin = require('autoprefixer');
const PostCssRTLCSS = require('postcss-rtlcss');
const PostCssCustomMediaCSS = require('postcss-custom-media');
@@ -17,6 +18,16 @@ const presets = require('../lib/presets');
@@ -17,6 +18,17 @@ const presets = require('../lib/presets');
const resolvePrivateEnvConfig = require('../lib/resolvePrivateEnvConfig');
const getLocalAliases = require('./getLocalAliases');

+console.log('If you are expecting to use the PORT from env.config, make sure to run `npm run postinstall` first!');
+let envConfig = {};
+const envConfigPathJs = path.resolve(process.cwd(),'./env.config.js');
+const envConfigPathJsx = path.resolve(process.cwd(), './env.config.jsx');
Expand All @@ -50,7 +53,7 @@ index 5ce7716..fe9888e 100644
// Add process env vars. Currently used only for setting the
// server port and the publicPath
dotenv.config({
@@ -174,7 +185,7 @@ module.exports = merge(commonConfig, {
@@ -174,7 +186,7 @@ module.exports = merge(commonConfig, {
// reloading.
devServer: {
host: '0.0.0.0',
Expand All @@ -59,38 +62,3 @@ index 5ce7716..fe9888e 100644
historyApiFallback: {
index: path.join(PUBLIC_PATH, 'index.html'),
disableDotRule: true,
diff --git a/node_modules/@edx/frontend-build/config/webpack.prod.config.js b/node_modules/@edx/frontend-build/config/webpack.prod.config.js
index 2879dd9..64c2e7b 100644
--- a/node_modules/@edx/frontend-build/config/webpack.prod.config.js
+++ b/node_modules/@edx/frontend-build/config/webpack.prod.config.js
@@ -12,6 +12,7 @@ const NewRelicSourceMapPlugin = require('@edx/new-relic-source-map-webpack-plugi
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
+const fs = require('fs');
const PostCssAutoprefixerPlugin = require('autoprefixer');
const PostCssRTLCSS = require('postcss-rtlcss');
const PostCssCustomMediaCSS = require('postcss-custom-media');
@@ -23,6 +24,22 @@ const HtmlWebpackNewRelicPlugin = require('../lib/plugins/html-webpack-new-relic
const commonConfig = require('./webpack.common.config');
const presets = require('../lib/presets');

+/** This condition confirms whether the configuration for the MFE has switched to a JS-based configuration
+ * as previously implemented in frontend-build and frontend-platform. If the environment variable exists, then
+ * an env.config.js file will be created at the root directory and its env variables can be accessed with getConfig().
+ *
+ * https://github.com/openedx/frontend-build/blob/master/docs/0002-js-environment-config.md
+ * https://github.com/openedx/frontend-platform/blob/master/docs/decisions/0007-javascript-file-configuration.rst
+ */
+const envConfigPath = process.env.JS_CONFIG_FILEPATH;
+if (envConfigPath) {
+ const envConfigFilename = envConfigPath.slice(envConfigPath.indexOf('env.config'));
+
+ fs.copyFile(process.env.JS_CONFIG_FILEPATH, envConfigFilename, (err) => {
+ if (err) { throw err; }
+ });
+}
+
// Add process env vars. Currently used only for setting the PUBLIC_PATH.
dotenv.config({
path: path.resolve(process.cwd(), '.env'),
23 changes: 23 additions & 0 deletions webpack.prod.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs');
const { createConfig } = require('@edx/frontend-build');

/** This condition confirms whether the configuration for the MFE has switched to a JS-based configuration
* as previously implemented in frontend-build and frontend-platform. If the environment variable exists, then
* an env.config.js file will be created at the root directory and its env variables can be accessed with getConfig().
*
* https://github.com/openedx/frontend-build/blob/master/docs/0002-js-environment-config.md
* https://github.com/openedx/frontend-platform/blob/master/docs/decisions/0007-javascript-file-configuration.rst
*/

const envConfigPath = process.env.JS_CONFIG_FILEPATH;

if (envConfigPath) {
const envConfigFilename = envConfigPath.slice(envConfigPath.indexOf('env.config'));
fs.copyFile(envConfigPath, envConfigFilename, (err) => {
if (err) { throw err; }
});
}

const config = createConfig('webpack-prod');

module.exports = config;

0 comments on commit 2ad54d9

Please sign in to comment.