I have added some json file to my library, but when I build it there is error my.json file not under rootDir.
Assuming you want to access the .json file as part of the application build process (i.e. not via http), you will will need to put it into the assets folder in your project.
More information about the folder structure of an Angular application here.
You can then follow the instructions here to access the data from your components.
Related
Is there a way to generate a file dynamically and inject it into /pages without saving it in this directory?
For example, if I'd like to create a Next.js plugin that adds example.com/build static page with timestamp of last compilation, or list file structure of the project.
I'm using Webpack to build my assets for Chrome Extension.
Usually in the /dist you should have some JS files, some HTML files, and manifest.json
Previously I had this file created somewhere and using 'copy-webpack-plugin' I simply copied that to the /dist folder,
like this:
But now, I need to generate this manifest.json dynamically. I need to make AJAX request, get some data needed in the manifest.json, generate this file, and then put it in the /dist folder.
I'm familiar with Node.js and I know how to get AJAX data. I may be able to google how to generate JSON file. But how can I connect this Node.js app with Webpack build I have no idea. Should I use a plugin?
Please help me with this. I'm using "webpack": "^3.0.0",
This is how I managed to implement this using transform method:
I have been importing data in the form of a JSON file into a React component:
import data from '../../public/json/data.json';
I am using the create-react-app tool, and when I run npm run build, as expected the data.json file is bundled as part of the build/static/main.js file.
What I would like is for this data.json file not to be bundled but to be referenced at run-time each time the component runs. I.e. so that it can be edited in the built app and for these edits to show in the app. I thought that by including it in my public (as opposed to src) folder this would work, but of course I am still importing it so it is bundled. Is there a way to reference it without bundling it?
Use the fetch API to retrieve the JSON file asynchronously.
Check out https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch for example implementations.
Say I have a web dir someserver.com/json/ that has directory listing enabled.
And say in that directory I have several <vcenter name> directories.
And say that in each someserver.com/<vcenter name> directory there is a bunch of JSON files.
Assuming that my AngularJS app is running on someserver.com.
Is there a way in angularJS to get a listing of the vcenter dirs and json files within?
I plan to build an web app that parses info from all the JSON files and formats them into individual tables.
I'm working on a js project that follows this directory structure:
/doc
/src
/test
/etc
This client-side js app can be configured by a server app (a whole separate application) via json. We define the structure, attributes, attributes description and allowed attribute values for that json data using some xml files. Those xml files are parsed by the server app so it can send a correct json object.
Should I create a new "dist" directory for that xmls as they are distributed to the server app team. Or should I put them in my doc directory as they in some way document the interface between the server and client apps. Or should I do something different? I'm asking for best practices.
Sounds like these files are a resource, so I would put them underneath a resource directory. Probably something like /src/resource or /resource.