首先,我需要说我对 Webpack 的基础知识知之甚少,这可能是我找不到解决方案的原因。
所以我知道为了加载图像,我需要一个路径,而不是将其作为字符串输入 require('path/to/image')
然后我得到了一个外部库,我需要在其中传递一个path
属性,其中放置了多个图像。它似乎不起作用,那么我如何将它们加载到我的网站中?
<CountrySelect
multi={false}
flagImagePath="../../../public/flags/" //folder with multiple images
/>
网络包配置:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const outputDirectory = 'dist';
module.exports = {
entry: './src/client/index.js',
output: {
path: path.join(__dirname, outputDirectory),
filename: 'bundle.js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg|jpg|jpeg)$/,
loader: 'url-loader?limit=100000'
}
]
},
devServer: {
historyApiFallback: true,
port: 3000,
open: true,
proxy: {
'/api': 'http://localhost:8080'
}
},
plugins: [
new CleanWebpackPlugin([outputDirectory]),
new HtmlWebpackPlugin({
template: './public/index.html',
favicon: './public/favicon.ico'
})
]
};