Webpack outputs wrong path for images

后端 未结 1 1864
时光说笑
时光说笑 2020-12-14 17:35

I\'m building a site with react and webpack. When I build the app with webpack and try to include images, the images are written to the build folder along with the other ass

相关标签:
1条回答
  • 2020-12-14 17:50

    You could try setting the name option for file-loader, as well as output.publicPath.

     output: {
         path: 'build/',
         file: 'bundle.js',
         publicPath: '/assets'
    }
    

    ...

    { 
         test: /\.(png|jpg)$/, 
         loader: 'file-loader?name=/img/[name].[ext]' 
    }
    

    Then the resolved url in your require will be:

    /assets/img/news-feed-icon.png
    
    0 讨论(0)
提交回复
热议问题