[EC-473] Add feature flag config and environment loaders to Desktop (#3389)
This commit is contained in:
parent
5c34e53280
commit
e2cb0cf11a
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"dev_flags": {},
|
||||
"flags": {}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
function load(envName) {
|
||||
return {
|
||||
...loadConfig(envName),
|
||||
...loadConfig("local"),
|
||||
};
|
||||
}
|
||||
|
||||
function log(configObj) {
|
||||
const repeatNum = 50;
|
||||
// eslint-disable-next-line
|
||||
console.log(`${"=".repeat(repeatNum)}\nenvConfig`);
|
||||
// eslint-disable-next-line
|
||||
console.log(JSON.stringify(configObj, null, 2));
|
||||
// eslint-disable-next-line
|
||||
console.log(`${"=".repeat(repeatNum)}`);
|
||||
}
|
||||
|
||||
function loadConfig(configName) {
|
||||
try {
|
||||
return require(`./${configName}.json`);
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.code === "MODULE_NOT_FOUND") {
|
||||
return {};
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
load,
|
||||
log,
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"devFlags": {},
|
||||
"flags": {}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"flags": {}
|
||||
}
|
|
@ -3,9 +3,15 @@ const { merge } = require("webpack-merge");
|
|||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
|
||||
const configurator = require("./config/config");
|
||||
const { EnvironmentPlugin } = require("webpack");
|
||||
|
||||
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
|
||||
|
||||
console.log("Main process config");
|
||||
const envConfig = configurator.load(NODE_ENV);
|
||||
configurator.log(envConfig);
|
||||
|
||||
const common = {
|
||||
module: {
|
||||
rules: [
|
||||
|
@ -69,6 +75,10 @@ const main = {
|
|||
{ from: "./src/locales", to: "locales" },
|
||||
],
|
||||
}),
|
||||
new EnvironmentPlugin({
|
||||
FLAGS: envConfig.flags,
|
||||
DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {},
|
||||
}),
|
||||
],
|
||||
externals: {
|
||||
"electron-reload": "commonjs2 electron-reload",
|
||||
|
|
|
@ -5,9 +5,14 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||
const { AngularWebpackPlugin } = require("@ngtools/webpack");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const configurator = require("./config/config");
|
||||
|
||||
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
|
||||
|
||||
console.log("Renderer process config");
|
||||
const envConfig = configurator.load(NODE_ENV);
|
||||
configurator.log(envConfig);
|
||||
|
||||
const common = {
|
||||
module: {
|
||||
rules: [
|
||||
|
@ -142,6 +147,10 @@ const renderer = {
|
|||
filename: "[name].[contenthash].css",
|
||||
chunkFilename: "[id].[contenthash].css",
|
||||
}),
|
||||
new webpack.EnvironmentPlugin({
|
||||
FLAGS: envConfig.flags,
|
||||
DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {},
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue