Skip to content

Instantly share code, notes, and snippets.

@furkanacaryes
Created February 3, 2020 07:50
Show Gist options
  • Save furkanacaryes/42c02df31075428d6366be0bf9144f63 to your computer and use it in GitHub Desktop.
Save furkanacaryes/42c02df31075428d6366be0bf9144f63 to your computer and use it in GitHub Desktop.
import mediaFilesJSON from "../../static/mediaFiles.json";
export const AssetHelper = {
use(what) {
const match = mediaFilesJSON.find(({ name }) => name === what);
if (!match) throw new Error(`No asset found with name '${what}'`);
require(`../../static/${match.path}`);
return match[process.env.NODE_ENV] || match.path;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment