I set up a config-overrides.js and I have an assets folder that contains my images folder. When I try to call an image, it does not show up.
I tried using require() but it doesn't work.
Here is my config-overrides.js
const path = require('path');
module.exports = function override(config, env) {
const aliasses = {
Main: path.resolve(__dirname, './src/'),
Component: path.resolve(__dirname, './src/components'),
Assets: path.resolve(__dirname, './src/assets'),
Layouts: path.resolve(__dirname, './src/layouts'),
Routes: path.resolve(__dirname, './src/routes'),
};
config.resolve.alias = {
...config.resolve.alias,
...aliasses
};
return config;
}
My image
<img src="Assets/images/image.png" alt="" />
UPDATE:
Here is the package.json of my project:
{
"name": "secrethaha",
"version": "0.1.0",
"private": true,
"dependencies": {
"antd": "^3.19.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"resolutions": {
"ajv": "6.9.1"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"babel-plugin-import": "^1.12.0",
"less-loader": "^5.0.0",
"react-app-rewired": "^2.1.3"
}
}
My latest addition is the react-app-rewired.
url-loaderyou should be able toimportthe images directly as i showed in my answer, Have you tried it ?