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

[discussion] good way to share files among client and server #43

Open
binora opened this issue Oct 5, 2017 · 15 comments
Open

[discussion] good way to share files among client and server #43

binora opened this issue Oct 5, 2017 · 15 comments

Comments

@binora
Copy link
Contributor

binora commented Oct 5, 2017

we currently share the config file among client and server by mirroring it. This won't scale when more files need to shared and there would be lots of moving parts. Need to find a clean way to keep things simple.

  1. Maybe we can run eject to get hold of webpack, but i'm not sure of other consequences it might have ( maybe none).

need more opinions.

@jakkra
Copy link
Owner

jakkra commented Oct 5, 2017

@binora
Copy link
Contributor Author

binora commented Oct 5, 2017

well, I also found this :

  1. https://medium.com/@ktruong008/absolute-imports-with-create-react-app-4338fbca7e3d
  2. https://github.com/timoxley/linklocal

I'm yet to test the above . Meanwhile, I'm also testing eject and trying out the links you mentioned.

@jakkra
Copy link
Owner

jakkra commented Oct 5, 2017

Awesome! #2 Seems nice and easy, still long path will be necessary thought. It will make some things easier, but all component imports will be very long

@binora
Copy link
Contributor Author

binora commented Oct 6, 2017

  1. with linklocal , things will get easier but we'll have to add an extra step to start the project.

  2. I also tried creating custom env variables for locales and config paths. But that would mean shifting the dot-dots to .env file from App.js

  3. Other method I thought of is to shift the locales and client.js inside client folder. Sure, it includes changes to server-side code but seems straightforward ( and can keep things simple for future? ).

What do you think ?

@jakkra
Copy link
Owner

jakkra commented Oct 6, 2017

Just found this: https://www.npmjs.com/package/clientconfig
Looks like exactly what we want?

@binora
Copy link
Contributor Author

binora commented Oct 6, 2017 via email

@jakkra
Copy link
Owner

jakkra commented Oct 6, 2017

I didn't think of any problem because of react app. Server side it just sends the config as a cookie, which can be retrieved client side. Maybe I miss something, couldn't it just be required in react as usual?

@jakkra
Copy link
Owner

jakkra commented Oct 6, 2017

I'll give it a test to have config as a cookie, otherwise we'll go with your proposal 2 or 3 :)

@binora
Copy link
Contributor Author

binora commented Oct 6, 2017 via email

@jakkra
Copy link
Owner

jakkra commented Oct 6, 2017

Couldn't get clientconfig to work server side, since react-create-app uses webpack proxy. Didn't manage to send the cookie.

@binora
Copy link
Contributor Author

binora commented Oct 10, 2017

hey, so what's the next step ?

@jakkra
Copy link
Owner

jakkra commented Oct 10, 2017

As I undertsand with .env the imports client side will need to be client/src/compoment/Clock.js?
And to import the config it would be just config, since it's in the root directory?
I don't like that the client/src part is necessary, however I really like the idea of not having relative import paths. So I think the pros are greater than the cons :)

@binora
Copy link
Contributor Author

binora commented Oct 14, 2017

Hey, I tried .env approach. Here's what i did :

  1. bump react-scripts version from 0.7.0 to 1.0.0 to support setting NODE_PATH
  2. I set NODE_PATH=src/ in .env in the client directory
  3. was able to import components like components/<Component>.js
  4. The problem is this :
    screen shot 2017-10-14 at 12 56 15 pm

Turns out it CRA guys dont' allow any other files outside of the NODE_PATH ( once you set it)
Here's a discussion

Have a look and let me know if I missed something. :)

@jakkra
Copy link
Owner

jakkra commented Oct 14, 2017

Okey, thanks for looking into it. Maybe we can just move them into source?

@jakkra
Copy link
Owner

jakkra commented Oct 14, 2017

Or there is probably a correct way to have pictures. Like some kind of asset folder. Could look up how it should be done in create react app.
I'm a little busy, but hopefully next week I have time to check it out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants