diff --git a/landing/webpack.config.cjs b/landing/webpack.config.cjs --- a/landing/webpack.config.cjs +++ b/landing/webpack.config.cjs @@ -1,6 +1,5 @@ const AssetsPlugin = require('assets-webpack-plugin'); const path = require('path'); -const webpack = require('webpack'); const { createProdBrowserConfig, @@ -66,39 +65,18 @@ }, }; -const alchemyKey = process.env.COMM_ALCHEMY_KEY; - module.exports = function (env) { - const rawBrowserConfig = + const browserConfig = env === 'prod' ? createProdBrowserConfig(baseProdBrowserConfig, babelConfig) : createDevBrowserConfig(baseDevBrowserConfig, babelConfig); - const browserConfig = { - ...rawBrowserConfig, - plugins: [ - ...rawBrowserConfig.plugins, - new webpack.DefinePlugin({ - 'process.env': { - COMM_ALCHEMY_KEY: JSON.stringify(alchemyKey), - }, - }), - ], - }; - const baseNodeConfig = createNodeServerRenderingConfig( + const nodeConfig = createNodeServerRenderingConfig( baseNodeServerRenderingConfig, babelConfig, ); - const nodeConfig = { - ...baseNodeConfig, + const nodeServerRenderingConfig = { + ...nodeConfig, mode: env === 'prod' ? 'production' : 'development', - plugins: [ - ...baseNodeConfig.plugins, - new webpack.DefinePlugin({ - 'process.env': { - COMM_ALCHEMY_KEY: JSON.stringify(alchemyKey), - }, - }), - ], }; - return [browserConfig, nodeConfig]; + return [browserConfig, nodeServerRenderingConfig]; }; diff --git a/lib/webpack/shared.cjs b/lib/webpack/shared.cjs --- a/lib/webpack/shared.cjs +++ b/lib/webpack/shared.cjs @@ -89,6 +89,8 @@ }; } +const alchemyKey = process.env.COMM_ALCHEMY_KEY; + function createProdBrowserConfig(baseConfig, babelConfig) { const browserConfig = createBaseBrowserConfig(baseConfig); const babelRule = getBrowserBabelRule(babelConfig); @@ -101,6 +103,7 @@ 'process.env': { NODE_ENV: JSON.stringify('production'), BROWSER: true, + COMM_ALCHEMY_KEY: JSON.stringify(alchemyKey), }, }), new MiniCssExtractPlugin({ @@ -166,6 +169,7 @@ 'process.env': { NODE_ENV: JSON.stringify('development'), BROWSER: true, + COMM_ALCHEMY_KEY: JSON.stringify(alchemyKey), }, }), new ReactRefreshWebpackPlugin(), @@ -231,7 +235,14 @@ }, ], }, - plugins: sharedPlugins, + plugins: [ + ...sharedPlugins, + new webpack.DefinePlugin({ + 'process.env': { + COMM_ALCHEMY_KEY: JSON.stringify(alchemyKey), + }, + }), + ], }; }