cannot import image with create-react-app

前端 未结 5 1382
悲&欢浪女
悲&欢浪女 2021-02-18 21:43

I\'m using create-react-app, and I am struggling to load images. I am following the instructions as specified here, but I keep seeing the following error:



        
5条回答
  •  温柔的废话
    2021-02-18 22:16

    By default, Create-React-App uses url-loader for files with size 10000 bytes

    that works fine in the development environment, but in production reduce error.

    For a production environment, you should change the value for the limit of bytes in order to enforce webpack use file-loader instead.

    If you have to eject your app modify webpack.config.prod.js file and change the limit of url-loader to 10 and will work as well

    {
     test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
     loader: require.resolve('url-loader'),
     options: {
     limit: 10,
     name: 'static/media/[name].[hash:8].[ext]',
    },
    

提交回复
热议问题