Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moving assets out of /public to /src #2

Closed
alucard87pl opened this issue Jul 24, 2019 · 2 comments
Closed

moving assets out of /public to /src #2

alucard87pl opened this issue Jul 24, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects

Comments

@alucard87pl
Copy link
Owner

Currently all the glyphs are contained in /public/vfx and referenced in code via

import glyphs from './glyphs';

glyphs.js is a file storing an array of JSON objects:

export const glyphs = [
  { id: 1, src: "./vfx/glyphs/glyph1.png", description: "Earth" },
  { id: 2, src: "./vfx/glyphs/glyph2.png", description: "Crater" },
...
  { id: 39, src: "./vfx/glyphs/glyph39.png", description: "Leo" },
];

export default glyphs;

For reasons beyond my comprehension, these files can't be held in /src because then importing doesn't work quite as well.

@alucard87pl alucard87pl added enhancement New feature or request help wanted Extra attention is needed labels Jul 24, 2019
@alucard87pl alucard87pl self-assigned this Jul 24, 2019
@alucard87pl alucard87pl added this to To do in ReactGate via automation Jul 24, 2019
@Kuboczoch
Copy link
Contributor

Kuboczoch commented Jul 24, 2019

import is for static files only and images like glyph01.png theoretically can be changed in the future. So they can be held in /public/vfx/glyphs.

If you have to do it, it will look like this:

import Img0 from '../images/0.png';
import Img1 from '../images/1.png';
import Img2 from '../images/2.png';
import Img3 from '../images/3.png';
import Img4 from '../images/4.png';
import Img5 from '../images/5.png';
import Img6 from '../images/6.png';
...

Unless you will use webpack and use this code:

function importAll(r) {
    let images = {};
    r.keys().map((item, index) => { images[item.replace('./', '')] = r(item); });
    return images;
}

const images = importAll(require.context('./images', false, '/\.png/'));

<img src={images['0.png']} />

The list of names (description) should be exported to increase legibility and ease of use in the future

Kuboczoch added a commit to Kuboczoch/reactgate that referenced this issue Jul 24, 2019
From table to another variable for assembling in another function
alucard87pl added a commit that referenced this issue Jul 24, 2019
@alucard87pl
Copy link
Owner Author

Closed and Resolved.

ReactGate automation moved this from To do to Done Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
ReactGate
  
Done
Development

No branches or pull requests

2 participants