svg icon 을 tag로 추가하는 부분에 대해서 문의 드립니다.
627
작성한 질문수 74
github 에 올려주신 sleact 소스에서 js 셋팅 부분을 가져다가 사용했습니다.
svg icon 을 tag로 자동완성해서 사용해보려 하고 있습니다.
원코드 typescript 로 작성된 부분을 빼고 작성해보려고 하고 있는데요
잘 불러 오지를 못하는 에러로 보입니다. 어떤 부분을 수정해야 될까요?
그리고 webpack.config.js 부분에서도 경고가 뜨고 있습니다. 원인이 무었인지 알수 있을까요?




위에 코드에서 보시다 시피 arrow_left.svg 아이콘을 불러오지 못하는 부분에서 에러가 발생하는것으로 보입니다.
package.json
{
"name": "securityService-front",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack serve --env development",
"build": "NODE_ENV=production webpack"
},
"author": "ZeroCho",
"license": "MIT",
"dependencies": {
"@ant-design/icons": "^4.6.2",
"@emotion/babel-plugin": "^11.2.0",
"@emotion/react": "^11.1.5",
"@emotion/styled": "^11.1.5",
"@loadable/component": "^5.14.1",
"antd": "^4.15.0",
"axios": "^0.21.1",
"cross-env": "^7.0.3",
"css-loader": "^5.2.0",
"file-loader": "^6.2.0",
"json-loader": "^0.5.7",
"moment-timezone": "^0.5.33",
"postcss-loader": "^5.2.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-refresh": "^0.10.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-times": "^3.1.12",
"resolve-url-loader": "^3.1.2",
"style-loader": "^2.0.0",
"swr": "^0.5.5",
"url-loader": "^4.1.1"
},
"devDependencies": {
"@babel/core": "^7.13.8",
"@babel/preset-env": "^7.13.8",
"@babel/preset-react": "^7.12.13",
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"babel-loader": "^8.2.2",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"prettier": "^2.2.1",
"webpack": "^5.24.2",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
}
}
webpack.config.js
const path = require('path');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const webpack = require('webpack');
const isDevelopment = process.env.NODE_ENV !== 'production';
const config = {
name: 'securityService',
mode: isDevelopment ? 'development' : 'production',
devtool: isDevelopment ? 'hidden-source-map' : 'inline-source-map',
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
'@hooks': path.resolve(__dirname, 'hooks'),
'@components': path.resolve(__dirname, 'components'),
'@layouts': path.resolve(__dirname, 'layouts'),
'@pages': path.resolve(__dirname, 'pages'),
'@utils': path.resolve(__dirname, 'utils'),
'@typings': path.resolve(__dirname, 'typings'),
'@lib': path.resolve(__dirname, 'lib'),
},
},
entry: {
app: './client',
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: { browsers: ['last 2 chrome versions'] },
debug: isDevelopment,
},
],
'@babel/preset-react',
],
env: {
development: {
plugins: [require.resolve('react-refresh/babel')],
},
},
},
exclude: path.join(__dirname, 'node_modules'),
},
{
test: /\.(ttf|eot|svg|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{ loader: 'file-loader' }],
},
{
test: /\.css?$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpg|gif)$/,
use: [{ loader: 'file-loader' }],
},
],
},
plugins: [new webpack.EnvironmentPlugin({ NODE_ENV: isDevelopment ? 'development' : 'production' })],
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/dist/',
},
devServer: {
historyApiFallback: true,
port: 3090,
publicPath: '/dist/',
// proxy: {
// '/api/': {
// target: 'http://localhost:3095',
// changeOrigin: true,
// },
// },
},
};
if (isDevelopment && config.plugins) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
config.plugins.push(new ReactRefreshWebpackPlugin());
}
if (!isDevelopment && config.plugins) {
}
module.exports = config;
client.jsx
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import App from '@layouts/App';
render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.querySelector('#app'),
);

components/AllIcon/index.js
export { default } from './AllIcon';
components/AllIcon/AllIcon.js
import React from 'react';
import * as svg from './svg';
function AllIcon({ name, className, style }) {
return React.createElement(svg[name], {
className,
style,
});
}
export default AllIcon;
components/AllIcon/svg/index.js
import { ReactComponent as arrow_left } from './arrow_left.svg';
import { ReactComponent as arrow_right } from './arrow_right.svg';
export { arrow_left, arrow_right };
아래 두분에서 경고가 발생하고 있습니다 . 타입을 바꾸라는 것 같은데..




답변 1
0
svg를 렌더링할 때 왜 저 방식으로 하시나요? 그냥 img src 로 하시면 될텐데요?
0
webpack.config.js 부분에서 발생하는 경고는 왜 나오는건가요? 설정이 변경된 부분이 있는건지..
제가 적용한 이미지 관련 부분 코드로 인한건가요?
0


javascript
Unresolved javascript function
typescript
Unresolved typescript function
webstorm 이 잘못 경고를 띄워주는 부분이라서
위에 두가지 옵션을 꺼주셔야 한다고 합니다.
다른분들도 참고하시면 좋을것 같아서 올려 봅니다.
넥스트 버젼 질문
0
75
2
로그인시 401 Unauthorized 오류가 뜹니다
0
88
1
무한 스크롤 중 스크롤 튐 현상
0
172
1
특정 페이지 접근을 막고 싶을 때
0
103
2
createGlobalStyle의 위치와 영향범위
0
93
2
인라인 스타일 리렌더링 관련
0
90
2
vsc 에서 npm init 설치시 오류
0
146
2
nextjs 15버전 사용 가능할까요?
0
157
1
화면 새로고침 문의
0
119
1
RTK에서 draft, state 차이가 있나요?
0
151
2
Next 14 사용해도 될까요?
0
452
1
next, node 버전 / 폴더 구조 질문 드립니다.
0
348
1
url 오류 질문있습니다
0
210
1
ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out
0
372
1
sudo certbot --nginx 에러
0
1271
2
Minified React error 콘솔에러 (hydrate)
0
467
1
카카오 공유했을 때 이전에 작성했던 글이 나오는 버그
0
245
1
프론트서버 배포 후 EADDRINUSE에러 발생
0
325
1
npm run build 에러
0
517
1
front 서버 npm run build 중에 발생한 에러들
0
381
1
서버 실행하고 브라우저로 들어갔을때 404에러
0
335
2
css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.
0
283
1
팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.
0
235
2
해시태그 검색에서 throttle에 관해 질문있습니다.
0
198
1





