create-react-app - where to put images for a srcSet? - create-react-app

I'm running json-server with a create-react-app application. Within the db.json file I have mock data:
"data": [
{
"id": 1,
"image": {
"src": "./images/test-480w.jpeg",
"srcSet": "./images/test-480w.jpeg 480w, ./images/test-800w.jpeg 800w",
"sizes": "(max-width: 600px) 480px, 800px"
}
}
}],
...
Within a React component I have:
...
<img src={data[0].image.src} sizes={data[0].image.sizes} srcSet={data[0].image.srcSet} />
...
But not sure where to put the images in the folder structure. Tried in the root and in public, but nothing is working.

Related

Error: "ios.bundleIdentifier" is not defined in your app.config.js and we can't update this file programmatically. Add the value

I am trying to deploy a React Native App using eas build.
The app builds successfully on Android but not on IOS.
I see this error message which says ios.bundleIdentifier is not defined in app.config.js
But... it IS defined, as can be seen here:
import 'dotenv/config';
export default {
"name": "raterepositoryapp",
extra: {
env: process.env.ENV,
uri: process.env.APOLLO_URI
},
"expo": {
"extra": {
"eas": {
"projectId": "ecf6c94b-c096-4a5b-ab41-8dfdd36de96b"
}
}
},
"slug": "rate-repository-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.webforprofessionals.rate-repository-app",
"buildNumber": "1.0.0"
},
"android": {
"package": "com.webforprofessionals.raterepositoryapp",
"versionCode": 1,
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
}
Why is the error coming up ?
I was able to finally discover the answer by using the EAS CLI command eas config --platform=ios --profile=preview (or whatever profile you want to test against). When you look at the output it gives you for app.config.js, you'll notice that there is no ios section shown and it's much smaller than your full app.config.js object. It is only using the eas portion of your app config.
I was able to fix the error by copying the ios config that's at the top-level of app.config.js into the expo portion of your config. I also moved the definition into a variable so I could use it in both places without repeating myself.
Edit:
After some more testing and documentation reading, I discovered what the real issue was. It appears that if you use app.config.js, the object you return is interpreted as the expo config... unless you also have an expo key inside that object. Then it only looks at what's in the expo part of your config. So what you really want to do is take your everything that's embedded under expo.extra and move it under extra.
Afterwards your app.config.js should look something like this:
export default {
name: "raterepositoryapp",
extra: {
env: process.env.ENV,
uri: process.env.APOLLO_URI,
eas: {
projectId: "ecf6c94b-c096-4a5b-ab41-8dfdd36de96b"
}
},
slug: "rate-repository-app",
// etc...
}
This is not obvious at all based on the error output, but after you realize which part of the file it's using, it's easy to address. I hope this works for you, too.
The documentation that tipped me off to this can be found here. You'll notice that wherever it uses the app.json format, you'll see everything nested under an expo key, but wherever it uses the app.config.js format, you'll see everything at the top-level of the object. That gave me the hint to start testing moving everything to the top level and do some testing.

Getting a 404 response back from my local host

I've been given a home assignment for a job interview. For me to get going I need to work with an API end point they've provided me but I can't get it running for some reason. It should be straight forward but I keep getting 404 back.
This is my package.json:
{
"name": "frontend-dev-assignment",
"version": "0.1.0",
"private": true,
"dependencies": {
"canned": "0.3.12"
},
"devDependencies": {
"concurrently": "3.5.1"
},
"scripts": {
"start": "canned -p 5000 ./api/"
},
"proxy": "http://localhost:5000"
}
In that same directory I have a folder named api and in it a file called _search.get.json. This is the contents of that file (shortened):
[
{
"term": "Abyssinian",
"resultCount": 61
},
{
"term": "Aegean",
"resultCount": 26
},
{
"term": "American Curl",
"resultCount": 56
}
]
In the parent folder I ran npm install and then npm start. I got this line in my CLI:
starting canned on port 5000 for C:\Users\Yanay\Documents\Coding\Autocomplete\api (Autocoplete is that parent folder).
But when I try to access http://localhost:5000/ or http://localhost:5000//search?q=xxxx I keep getting a 404 back.
What could I be doing wrong here?

Cumulocity plugin style

i'm trying to add a stylesheet to my plugin. I followed this and added a styles folder and my css "glstyle.css" inside, then my cumulocity.json looks like this:
{
"name": "Occupation Stats",
"description": "Parking spot occupation statistics",
"ngModules": [
"glsmartparking-v3.occupationstats"
],
"js": [
"index.js",
"dateutil.js",
"controllers/ocs-controller.js"
],
"css": [
"styles/glstyle.css"
]
}
But the css isn't loaded in the page. Am I doing something wrong?
Have you registered your plugin again with grunt pluginRegister:<pluginName> after changing its manifest in cumulocity.json?

There is no 'package.json' - node-webkit app

I'm making my first desktop application using node-webkit.
I followed all the steps to package the app on windows but I'm getting this error:
There is no 'package.json' in the package, please make sure the 'package.json' is in the root of the package.
Although the package is in the root.
sample package.json file
{
"name": "name of app",
"version": "1.0.0",
"main": "index.html",
"single-instance": true,
"node-remote": "<local>",
"window": {
"title": "name to show in title bar",
"icon": "icon to show in titlebar",
"position": "center",
"min_width": 1024,
"min_height": 600,
"toolbar": true,
"width": 1362,
"height": 768
},
"dependencies": {
"express": "3.x"
},
"webkit": {
"plugin": true
}
}
Ok I found my mistake. In fact, I was compressing the folder containing the package json and the other files. So what I made was like that:
App.zip
|
|-App
|-package.json
|-Other files
What is correct is this:
App.zip
|-package.json
|-Other files

What is the proper way to load an external javascript in Sencha Touch 2

In my development I need to include third part javascripts; like money.js (http://josscrowcroft.github.com/money.js/)
What is the best 'clean'/'proper' way to achieve it ? Just include it in index.html ?
No. Don't directly add the additional javascript files in the index.html file. That is not the recommended way (though it may work).
Instead, do like this,
Include the following line in your index.html. microloader is the folder that is shipped with sencha sdk and contains three files mainly, development.js, production.js and testing.js , each one for it's own purpose.
< script id ="microloader" type="text/javascript" src="../../microloader/development.js"> < /script >
Then, in your <appname> folder, you will need to have a file called as app.json. It will look something like this ..
{
"name": "Sencha",
// All javascript files go here ...
"js": [
{
"path": "../../sencha-touch-all-debug.js"
},
{
"path": "app.js",
"update": "delta"
},
{
"path": "http://josscrowcroft.github.com/money.js/",
"update": "delta"
}
],
"css": [
{
"path": "../../resources/css/sencha-touch.css",
"update": "delta"
},
{
"path": "resources/css/app.css",
"update": "delta"
}
],
.....
.....
.....
}
If you are using Sencha Cmd your index.html may look like this:
<!-- The line below must be kept intact for Sencha Command to build your application -->
<script id="microloader" type="text/javascript" src=".sencha/app/microloader/development.js"></script>
So after changing app.json you'll need to refresh your app:
sencha app refresh
Pure javascript did the trick for me. I just included this block of code in the launch function:
var scriptTag = document.createElement('script');
scriptTag.src = 'specify the path here...';
document.body.appendChild(scriptTag);
The scriptTag gets appended into the body of your index file.
The following worked for me with Ext JS 5.0.0, if the external JavaScript library is local. After the editing, run "sencha app build"
Make changes to three JSON elememtns in app.json.
(1) js
(2) css
(3) resources
{
"name": "Sencha",
// All javascript files go here ...
"js": [
{
"path": "app.js",
"bundle": true
},
{
"path": "leaflet/leaflet.js",
"bundle": true
}
],
"css": [
{
"path": "bootstrap.css",
"bootstrap": true
},
{
"path": "leaflet/leaflet.css",
"bootstrap": true
}
],
.....
/**
* Extra resources to be copied along when build
*/
"resources": [""leaflet/leaflet.js","leaflet/leaflet.css"
],
.....
.....
}