generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move webpack config logic to node_modules via patch-package
* add JS/JSX compatability to jest and webpack configs
- Loading branch information
Showing
5 changed files
with
205 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
diff --git a/node_modules/@edx/frontend-build/config/jest.config.js b/node_modules/@edx/frontend-build/config/jest.config.js | ||
index ae08b70..952ccc3 100644 | ||
--- a/node_modules/@edx/frontend-build/config/jest.config.js | ||
+++ b/node_modules/@edx/frontend-build/config/jest.config.js | ||
@@ -3,12 +3,12 @@ const fs = require('fs'); | ||
|
||
const presets = require('../lib/presets'); | ||
|
||
-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; | ||
-} | ||
+const envConfigPath = fs.existsSync(appEnvConfigPathJs) ? appEnvConfigPathJs | ||
+ : fs.existsSync(appEnvConfigPathJsx) ? appEnvConfigPathJsx | ||
+ : path.resolve(__dirname, './jest/fallback.env.config.js'); | ||
|
||
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..932a853 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'); | ||
const dotenv = require('dotenv'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const path = require('path'); | ||
+const fs = require('fs'); | ||
const PostCssAutoprefixerPlugin = require('autoprefixer'); | ||
const PostCssRTLCSS = require('postcss-rtlcss'); | ||
const PostCssCustomMediaCSS = require('postcss-custom-media'); | ||
@@ -17,6 +18,12 @@ const presets = require('../lib/presets'); | ||
const resolvePrivateEnvConfig = require('../lib/resolvePrivateEnvConfig'); | ||
const getLocalAliases = require('./getLocalAliases'); | ||
|
||
+const envConfigPathJs = path.resolve(process.cwd(),'./env.config.js'); | ||
+const envConfigPathJsx = path.resolve(process.cwd(), './env.config.jsx'); | ||
+const envConfig = fs.existsSync(envConfigPathJs) ? require(envConfigPathJs) | ||
+ : fs.existsSync(envConfigPathJsx) ? require(envConfigPathJsx) | ||
+ : {}; | ||
+ | ||
// Add process env vars. Currently used only for setting the | ||
// server port and the publicPath | ||
dotenv.config({ | ||
@@ -174,7 +181,7 @@ module.exports = merge(commonConfig, { | ||
// reloading. | ||
devServer: { | ||
host: '0.0.0.0', | ||
- port: process.env.PORT || 8080, | ||
+ port: envConfig.PORT || process.env.PORT || 8080, | ||
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'), |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.