我需要链接来自“全局”路径的图像,这是不在webpack服务的应用程序内部的路径。我做过类似的事情:
<img src="/users/name/home/Desktop/test.svg"/>
,但我无法看到图像,如果用检查器看一下img元素,我看到路径是这样的:
http://localhost:8080/users/name/home/Desktop/test.svg
我认为原因是所有这些图像都是由webpack提供的,但我不知道如何改变这种行为。 这是我的webpack dev配置文件:
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { spawn } = require('child_process');
const redis = require('redis')
// Config directories
const SRC_DIR = path.resolve(__dirname, 'src');
const OUTPUT_DIR = path.resolve(__dirname, 'dist');
// Any directories you will be adding code/files into, need to be added to this array so webpack will pick them up
const defaultInclude = [SRC_DIR];
module.exports = {
entry: SRC_DIR + '/index.js',
output: {
path: OUTPUT_DIR,
publicPath: '/',
filename: 'bundle.js'
},
resolve: {
alias: {
'hiredis': path.join(__dirname, 'aliases/hiredis.js')
}
},
module: {
rules: [
{
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader']
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' },
{ loader: 'css-loader' }],
include: defaultInclude
},
{
test: /\.jsx?$/,
use: [{ loader: 'babel-loader' }],
include: defaultInclude
},
{
test: /\.(jpe?g|png|gif)$/,
use: [{ loader: 'file-loader?name=img/[name]__[hash:base64:5].[ext]' }],
include: defaultInclude
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: [{ loader: 'file-loader?name=font/[name]__[hash:base64:5].[ext]'}],
include: defaultInclude
}
]
},
target: 'electron-renderer',
plugins: [
new HtmlWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
devtool: 'cheap-source-map',
devServer: {
contentBase: OUTPUT_DIR,
stats: {
colors: true,
chunks: false,
children: false
},
setup() {
spawn(
'electron',
['.'],
{ shell: true, env: process.env, stdio: 'inherit' }
)
.on('close', code => process.exit(0))
.on('error', spawnError => console.error(spawnError));
}
}
};
由于
保