Devlog/Web

[React] ์ด๋ฏธ์ง€ํŒŒ์ผ import ์‹คํŒจ ์—๋Ÿฌ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

FATKITTY 2021. 8. 4. 01:10
๋ฐ˜์‘ํ˜•

๐Ÿ’ข ์ด๋ฏธ์ง€ํŒŒ์ผ import ์‹คํŒจ

 

โ–ช์—๋Ÿฌ๋‚ด์šฉ : png react Module parse failed: Unexpected character (1:0)

 

โ–ช์›์ธ : ์ด๋ฏธ์ง€ํŒŒ์ผ loader ๋ถ€์žฌ

 

โ–ชํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

1. install file-loader

$ npm install file-loader --save-dev

2. add loader to webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.(png|jpe?g|gif)$/i,
        use: [
          {
            loader: 'file-loader',
          },
        ],
      },
    ],
  },
};

webpack.config.js

1, 2๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ์ˆ˜ํ–‰ํ•œ ํ›„์— ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ๋‹ค์‹œ import ํ•ด๋ณด๋ฉด ๋ฌธ์ œ์—†์ด ์ž˜ ์ปดํŒŒ์ผ๋œ๋‹ค.

 

 

์ฐธ๊ณ ์ž๋ฃŒ

https://v4.webpack.js.org/loaders/file-loader/

๋ฐ˜์‘ํ˜•