Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1282 from govau/ji-skin-env-settings
Browse files Browse the repository at this point in the history
webpack: allow skins to add extra env variables
  • Loading branch information
jcscottiii authored Nov 14, 2017
2 parents 1e1ab77 + 7be02b1 commit 8964191
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ const CG_STYLE_PATH = process.env.CG_STYLE_PATH;

const SKIN_NAME = process.env.SKIN_NAME || 'cg';

// getSkinEnv looks in the skin module for an `env.js` file which is expected to
// contain an array of additional environment variable names that should be
// added to the webpack DefinePlugin.
// If the skin's env module is not found, an empty array is returned: this
// makes the feature opt-in for skins.
const getSkinEnv = () => {
const mod = path.resolve(
__dirname,
`static_src/skins/${SKIN_NAME}/env`
);

try {
require.resolve(mod);
} catch (e) {
return [];
}

return require(mod); // eslint-disable-line import/no-dynamic-require, global-require
};

const srcDir = './static_src';
const compiledDir = './static/assets';

Expand Down Expand Up @@ -102,6 +122,12 @@ if (PRODUCTION) {
processEnv.NODE_ENV = JSON.stringify('production');
}

const skinEnv = getSkinEnv();

skinEnv.forEach((env) => {
processEnv[env] = JSON.stringify(process.env[env]);
});

config.plugins.push(
new webpack.DefinePlugin({
'process.env': processEnv
Expand Down

0 comments on commit 8964191

Please sign in to comment.