Commit ae43f68a authored by Matija Obreza's avatar Matija Obreza

ISO3_FLAGS constant generated at compile time

parent 863649c8
......@@ -4,6 +4,7 @@ const webpackMerge = require('webpack-merge');
const MinifyPlugin = require('terser-webpack-plugin');
const commonConfig = require('./webpack-base.config.js');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const fs = require('fs');
// other
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
......@@ -58,7 +59,10 @@ module.exports = {
'process.env': {
NODE_ENV: JSON.stringify(IS_PRODUCTION ? 'production' : 'development'),
ALLOW_ROBOTS: JSON.stringify(ALLOW_ROBOTS ? 'true' : 'false'),
}
},
'ISO3_FLAGS': JSON.stringify(fs.readdirSync(path.join(process.cwd(), 'assets/images/flags')).map((s) => {
return s.slice(0, -4);
})),
}),
new CopyWebpackPlugin([
......
......@@ -313,7 +313,7 @@ module.exports = {
}),
new webpack.DefinePlugin({
'ISO3_FLAGS': JSON.stringify(fs.readdirSync(path.join(process.cwd(), 'assets/images/flags')).map((s) => {
ISO3_FLAGS: JSON.stringify(fs.readdirSync(path.join(process.cwd(), 'assets/images/flags')).map((s) => {
return s.slice(0, -4);
}))
}),
......
// The static list of flags available in assets/images/flags
// generated by webpack.DefinePlugin
declare const ISO3_FLAGS: string[];
declare let ISO3_FLAGS: Array<string>;
if (typeof window !== 'undefined') {
export const flagAssetExists = (iso3) => {
if (typeof ISO3_FLAGS !== 'undefined') {
return ISO3_FLAGS && ISO3_FLAGS.some((code) => code === iso3);
} else {
return true;
......
......@@ -22,6 +22,9 @@
"types": [
"node",
"webpack-env"
],
"typeRoots" : [
"./src/typings"
]
},
"exclude": [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment