Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Webpack client variables #1607

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ globals:
context: true
jestPuppeteer: true
BASE_URL: true
webpackConfig: true
rules:
camelcase: off # require camel case names
prefer-template: off
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ i18n
fallbackLng: "en",
/* To debug any errors w.r.t. i18n, swith the second `false` to `true`
(and this can be kept even after deployment if needed) */
debug: process.env.NODE_ENV === 'production' ? false : false, // eslint-disable-line
debug: webpackConfig.NODE_ENV === 'production' ? false : false, // eslint-disable-line
interpolation: {
escapeValue: false
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const configureStore = (initialState) => {
window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : (f) => f
);
const store = createStore(rootReducer, initialState, composedEnhancers);
if (process.env.NODE_ENV !== 'production' && module.hot) {
if (webpackConfig.NODE_ENV !== 'production' && module.hot) {
// console.log("hot reducer reload"); // eslint-disable-line
module.hot.accept('../reducers', () => {
const nextRootReducer = require('../reducers/index'); // eslint-disable-line global-require
Expand Down
6 changes: 3 additions & 3 deletions src/util/extensions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

const registry = (() => {
if (!process.env.EXTENSION_DATA) {
if (!webpackConfig.EXTENSION_DATA) {
// console.log("no EXTENSION_DATA found");
return {};
}

const extensions = typeof process.env.EXTENSION_DATA === "string" ?
JSON.parse(process.env.EXTENSION_DATA) : process.env.EXTENSION_DATA;
const extensions = typeof webpackConfig.EXTENSION_DATA === "string" ?
JSON.parse(webpackConfig.EXTENSION_DATA) : webpackConfig.EXTENSION_DATA;

Object.keys(extensions).forEach((key) => {
if (key.endsWith("Component")) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/googleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const initialiseGoogleAnalyticsIfRequired = async () => {
}
importReactGa = import("react-ga");
ReactGA = (await importReactGa).default;
if (process.env.NODE_ENV !== "production") {
if (webpackConfig.NODE_ENV !== "production") {
// eslint-disable-next-line
console.log("Not setting up Google Analytics as we are not in production mode");
return;
Expand Down
14 changes: 6 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
}

/* plugins */
/* inject strings into the client-accessible process.env */
const pluginProcessEnvData = new webpack.DefinePlugin({
"process.env": {
NODE_ENV: devMode ? JSON.stringify("development") : JSON.stringify("production"),
EXTENSION_DATA: JSON.stringify(extensionData)
}
/* inject client-accessible variables */
const pluginClientVariables = new webpack.DefinePlugin({
"webpackConfig.NODE_ENV": devMode ? JSON.stringify("development") : JSON.stringify("production"),
"webpackConfig.EXTENSION_DATA": JSON.stringify(extensionData)
});
/* gzip everything - https://github.com/webpack-contrib/compression-webpack-plugin */
const pluginCompress = new CompressionPlugin({
Expand All @@ -89,13 +87,13 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
const plugins = devMode ? [
new LodashModuleReplacementPlugin(),
new webpack.HotModuleReplacementPlugin(),
pluginProcessEnvData,
pluginClientVariables,
new webpack.NoEmitOnErrorsPlugin(),
pluginHtml,
cleanWebpackPlugin
] : [
new LodashModuleReplacementPlugin(),
pluginProcessEnvData,
pluginClientVariables,
pluginCompress,
pluginHtml,
cleanWebpackPlugin
Expand Down