Move imports to a separate file

Viewed 109

I have a huge number of picture imports like this:

imports

In the html code this pictures were used like:

<source
  media="(min-width: 1200px)"
  srcset="/images/DISCLAIMER.jpg, /images/disclaimer-1140@2x.png 2x, /images/disclaimer-1140@3x.png 3x"
></source>

Question: How can I move all the imports to a separate file and export them like disclaimer['320']['3x']? Maybe you know the example of this case.

1 Answers

Do this:

Create file(let's call it asset.js) and import assets you want and then export them:

import disclaimer from '...'
import disclaimer_3x from '...'

const disclaimer = {
  320: {
    3x: disclaimer_3x
  }
}

export {
  disclaimer
}

then just import this file:

import * as Asset from 'asset.js'

and use them like this:

Asset.disclaimer['320']['3x']
Related