You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
I have an helper function, which sets the appContext based on if its server or client code, since they live in two separate packages.
// webpack.helper.jsimportConfig,{environment}from'webpack-config'/* Basic helper that fetches respective config based on the path and configName. localWebpackPath -> e.g. /path/to/server/webpack, localContextPath -> e.g. /path/to/server/src localConfigName -> e.g. server.webpack.js*/exportfunctionfetchConfig(localWebpackPath,localContextPath,localConfigName=''){// based on who invoked set the environment variables.environment.setAll({root: ()=>'path/to/common/webpack/files',// root has base.js, prod.js, dev.jsappContext: localContextPath// source of the target webpack to resolve modules})consttoExport=[]//based on the name and location fetch the config.toExport.push(...load(localConfigName,localWebpackPath)if(!toExport.length){// if no config could be constructed throw error.console.error('Error: WEBPACK_CONFIG files not given')process.exit()}returntoExport}// Helper to require the webpack file and merge them to one incase they exported arrays.functionload(file,localpath=''){try{wp=require(path.resolve(localpath,file)).default}catch(e){console.error(`Error: ${file}.js not found or has errors:`)// eslint-disable-line no-consoleconsole.error(e)// eslint-disable-line no-consoleprocess.exit()}// If the config isn't already an array, add it to a new one, map over each// `webpack-config`, and create a 'regular' Webpack-compatible objectreturn(Array.isArray(wp) ? wp : [wp]).map(config=>newConfig().merge(config).toObject())}...
webpack.config.babel.js that invokes server.webpack.js
// client/webpack.config.babel.jimport{fetchConfig}from'path/to/common/helpers/webpack.helper'importpathfrom'path'constlocalWebpackPath=path.join(__dirname,'webpack')constlocalContextPath=path.join(__dirname,'src')letlocalConfigName='client.webpack.js'// just feed the path, based on the environment, helper will pick the corresponding webpack file.exportdefaultfetchConfig(localWebpackPath,localContextPath,localConfigName)------------------------------------------------------------------------------------------------// server/webpack.config.babel.jimport{ fetchConfig }from'path/to/common/helpers/webpack.helper'importpathfrom'path'constlocalWebpackPath=path.join(__dirname,'webpack')constlocalContextPath=path.join(__dirname,'src')letlocalConfigName='server.webpack.js'// just feed the path, based on the environment, helper will pick the corresponding webpack file.exportdefaultfetchConfig(localWebpackPath,localContextPath,localConfigName)
Now i can invoke and get the files merged, but the context got from base.js to server/client webpack files always have the one injected when client webpack was invoked.
Not sure what i'm missing out here or if the recommended way to inject the environment/reusable variable is wrong. Please let me know if there is way to achieve this.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have an issue in way we reuse environment variables per config. Let me explain below
Now i can invoke and get the files merged, but the context got from base.js to server/client webpack files always have the one injected when client webpack was invoked.
Not sure what i'm missing out here or if the recommended way to inject the environment/reusable variable is wrong. Please let me know if there is way to achieve this.
The text was updated successfully, but these errors were encountered: