์ด๊ฑธ ์์ง๋ ํท๊ฐ๋ฆฌ๋ ๋๋ฅผ ์ํด ์ ๋ฆฌ๋ฅผ ํด๋ณธ๋ค
์๋๊ฒฝ๋ก
๊ฐ์ ํด๋ ๋ด
์ฝ๊ฒ ์ดํดํ๊ธฐ ์ํด ์น๋์์ธ ๊ธฐ๋ฅ์ฌ ๊ณต๋ถํ ๋ ํด๋๋ฅผ ๊ฐ์ ธ์์
๋์ผํ ์์น์ ์ ์ฅ๋์ด ์๊ธฐ ๋๋ฌธ์, "ํ์ผ๋ช .ํ์ฅ์" ๋ก ๊ธฐ์ ํด์ฃผ๋ฉด ๋๋ค.
<link rel="icon" href="favicon.png">
ํ์ ํด๋
index.html ๊ธฐ์ค์ผ๋ก ๋ฐ์ ์๋ ํ์ผ/ ์ด๋ฏธ์ง๋ค์ ๋ถ๋ฌ์ค๊ธฐ ์ํ ๊ฒฝ๋ก๋
./ : ํ์ฌ ๋๋ ํ ๋ฆฌ์,
ํด๋๋ฅผ ๋ค์ด๊ฐ๋ค๋ ์๋ฏธ์ ์ฌ๋์(/)๋ฅผ ์ฌ์ฉํด์ฃผ๋ฉด ๋๋ค!
<link rel="stylesheet" href="./css/style.css" />
<script src="./script/script.js"></script>
..
<img src="./images/logo.png" alt="๋ก๊ณ " />
์์ ํด๋
style.css๊ธฐ์ค์ผ๋ก images ํด๋์ ์๋ ์ด๋ฏธ์ง๋ฅผ ๋ถ๋ฌ์ฌ ๋๋,
์ผ๋จ ํ์ฌ ์๋ ํด๋๋ฅผ ๋ฒ์ด๋ ์์ํด๋๋ก(../) ๊ฐ์ผํ๋ค.
๊ทธ ๋ค์, images ํด๋๋ก ๋ค์ด๊ฐ๋ค.
header .logo {
background: url(../images/logo.png) no-repeat;
}
- / : ๊ฐ์ฅ ์ต์์ ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ๋ค.
- ./ : ํ์ผ์ด ํ์ฌ ๋๋ ํ ๋ฆฌ๋ฅผ ์๋ฏธํ๋ค.
- ../:์์ ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ๋ค.
- ๋๋จ๊ณ ์์ ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ๋ ค๋ฉด? ../../
์ ๋๊ฒฝ๋ก
js ์์๋ process.env.PUBLIC_URL
html ์์๋ %PUBLIC_URL%
๊ฐ๋จํ๊ฒ ๋งํ๋ฉด ์ด๋ ๋ค.
์ ๋๊ฒฝ๋ก๋ฅผ ์ข์ํ๋ ํธ์ด๋ผ.. ๊ฐ๋จํ๊ฒ ์ง๊ณ ๋์ด๊ฐ๋ฉด ๋ ๊ฑฐ ๊ฐ์ง๋ง
public ํด๋ ๋ด images ํด๋ ์์ ์๋ ์ฌ์ง!์ ๊ฐ์ ธ์ค๊ณ ์ถ๋ค๋ฉด,(js)
<img src={process.env.PUBLIC_URL + '/images/logo.png'} />
์ด๋ ๊ฒ ์จ์ฃผ๋ฉด ๋!
'์ฝ๋ฉ ๋ฉ๋ชจ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[error] Parsing error: 'import' and 'export' may only appear at the top level. (0) | 2023.05.20 |
---|---|
[error] Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'. (0) | 2023.05.20 |
error : Uncaught TypeError: Cannot read properties of null ~ (1) | 2023.05.20 |
git master main ํฉ์น๊ธฐ (0) | 2023.05.19 |
React์์ importํ ๋ {}์ค๊ดํธ ์ ๋ฌด์ ์๋ฏธ! (0) | 2023.05.19 |