请帮助配置文件加载器,以便在具有这种结构的项目中
我可以以类似的方式从公用文件夹中获取图像:
<img src={"/images/globalx_logo.svg"} className="globalx-logo"/>
为了尝试做某事,我写了这个 webpack.config.js:
var path = require('path')
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, './output'),
publicPath: '/output/',
filename: 'bundle.js'
},
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"]
}
},
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.(jpg|png|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: './public/',
outputPath: './output/public/'
}
}
]
}
}