diff --git a/config/webpack/productionConfig.js b/config/webpack/productionConfig.js new file mode 100644 index 000000000000..594d616ac423 --- /dev/null +++ b/config/webpack/productionConfig.js @@ -0,0 +1,29 @@ +const webpack = require('webpack'); +const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer'); + +/** + * Get the production webpack configuration, given an environment object. + * + * @param {Object} env + * @returns {Object} + */ +function getProductionConfig(env) { + return ({ + mode: 'production', + devtool: 'source-map', + plugins: [ + // This allows us to interactively inspect JS bundle contents + ...(process.env.ANALYZE_BUNDLE === 'true' ? [new BundleAnalyzerPlugin()] : []), + new webpack.DefinePlugin({ + __REACT_WEB_CONFIG__: JSON.stringify(env), + + // React Native JavaScript environment requires the global __DEV__ variable to be accessible. + // react-native-render-html uses variable to log exclusively during development. + // See https://reactnative.dev/docs/javascript-environment + __DEV__: false, + }), + ], + }); +} + +module.exports = getProductionConfig; diff --git a/config/webpack/webpack.prod.js b/config/webpack/webpack.prod.js index a6c6d4175dd7..c9b3bdb6d007 100644 --- a/config/webpack/webpack.prod.js +++ b/config/webpack/webpack.prod.js @@ -1,25 +1,9 @@ const path = require('path'); -const webpack = require('webpack'); const {merge} = require('webpack-merge'); -const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer'); const dotenv = require('dotenv'); const common = require('./webpack.common.js'); +const getProductionConfig = require('./productionConfig'); const env = dotenv.config({path: path.resolve(__dirname, '../../.env.production')}).parsed; -module.exports = merge(common, { - mode: 'production', - devtool: 'source-map', - plugins: [ - // This allows us to interactively inspect JS bundle contents - ...(process.env.ANALYZE_BUNDLE === 'true' ? [new BundleAnalyzerPlugin()] : []), - new webpack.DefinePlugin({ - __REACT_WEB_CONFIG__: JSON.stringify(env), - - // React Native JavaScript environment requires the global __DEV__ variable to be accessible. - // react-native-render-html uses variable to log exclusively during development. - // See https://reactnative.dev/docs/javascript-environment - __DEV__: false, - }), - ], -}); +module.exports = merge(common, getProductionConfig(env)); diff --git a/config/webpack/webpack.staging.js b/config/webpack/webpack.staging.js index 2329b92ee020..50469af3dc45 100644 --- a/config/webpack/webpack.staging.js +++ b/config/webpack/webpack.staging.js @@ -1,25 +1,9 @@ const path = require('path'); -const webpack = require('webpack'); const {merge} = require('webpack-merge'); -const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer'); const dotenv = require('dotenv'); const common = require('./webpack.common.js'); +const getProductionConfig = require('./productionConfig'); const env = dotenv.config({path: path.resolve(__dirname, '../../.env.staging')}).parsed; -module.exports = merge(common, { - mode: 'production', - devtool: 'source-map', - plugins: [ - // This allows us to interactively inspect JS bundle contents - ...(process.env.ANALYZE_BUNDLE === 'true' ? [new BundleAnalyzerPlugin()] : []), - new webpack.DefinePlugin({ - __REACT_WEB_CONFIG__: JSON.stringify(env), - - // React Native JavaScript environment requires the global __DEV__ variable to be accessible. - // react-native-render-html uses variable to log exclusively during development. - // See https://reactnative.dev/docs/javascript-environment - __DEV__: false, - }), - ], -}); +module.exports = merge(common, getProductionConfig(env));