Created
February 3, 2020 07:50
-
-
Save furkanacaryes/42c02df31075428d6366be0bf9144f63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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