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

json files do not get copied over in build-react-component #407

Closed
redbmk opened this issue Nov 30, 2017 · 4 comments
Closed

json files do not get copied over in build-react-component #407

redbmk opened this issue Nov 30, 2017 · 4 comments

Comments

@redbmk
Copy link

redbmk commented Nov 30, 2017

This issue is a:

  • Bug report
  • Question / support request

I built a component using nwb new react-component my-component. In a few places in src I have a few .json files, which I can import with import asdf from './asdf.json' and it works just fine when running the demo with yarn start.

However, when I go to build the component with yarn build the .json files are missing from the es and lib folders, so the files fail to import when used elsewhere.

The workaround I found for now is a somewhat messy bash oneliner, which I then added to package.json as a postbuild so it gets run automatically after the build.

find src -name '*.json' | grep -o '/.*' | xargs -I% bash -c 'cp src% es%; cp src% lib%'
diff --git a/package.json b/package.json
index b72d65a..5a20d7e 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
   ],
   "scripts": {
     "build": "nwb build-react-component",
+    "postbuild": "find src -name '*.json' | grep -o '/.*' | xargs -I% bash -c 'cp src% es%; cp src% lib%'",
     "clean": "nwb clean-module && nwb clean-demo",
     "start": "nwb serve-react-demo",
     "test": "nwb test-react",

It would be awesome if I didn't have to do this. Is there a config I missed somewhere, or is this a bug?

@insin
Copy link
Owner

insin commented Nov 30, 2017

There's a --copy-files flag you can use for this - those docs could do with some headers to make the flags stand out more.

@redbmk
Copy link
Author

redbmk commented Nov 30, 2017

Nice, that did the trick! Thanks @insin. I kept searching for json in the docs and didn't see anything. I think it would have helped me if instead of

such as CSS files

it said

such as CSS or JSON files

Maybe adding some more examples would help other people.

insin added a commit that referenced this issue Dec 2, 2017
Add headings for feature toggles so they're easier to find

Mention JSON files in --copy-files docs #407

[ci skip]
@insin
Copy link
Owner

insin commented Dec 2, 2017

Hopefully this is a little easier to find now

@insin insin closed this as completed Dec 2, 2017
@redbmk
Copy link
Author

redbmk commented Dec 2, 2017

Awesome, thanks for the quick update!

insin added a commit that referenced this issue Dec 5, 2017
Add headings for feature toggles so they're easier to find

Mention JSON files in --copy-files docs #407

[ci skip]
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