我有一个React/Redux应用程序,正在使用webpack转换我的JSX和ES6并将样式表和图像加载到JS中。我的开发服务器托管在端口3000上。
这是我的webpack.config.js:
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'webpack-hot-middleware/client',
'./src/js'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
favicon: 'src/images/favicon.ico'
})
],
module: {
loaders: [{
test: /\.js$/,
loaders: [ 'babel' ],
exclude: /node_modules/,
include: __dirname
}, {
test: /\.less?$/,
loaders: [ 'style', 'css', 'less' ],
include: __dirname
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loaders: [ 'url' ],
include: __dirname
},
{
test: /\.(png|ico|gif)?$/,
loaders: [ 'file' ],
include: __dirname
}]
}
};
当我点击localhost:3000时,除了我的收藏夹图标,所有我希望在那里的东西都在那里。如果我转到localhost:3000/static/favicon.ico,我的收藏夹就在那里。可以使用一些专业知识来调试此问题。
最佳答案
浏览器将在localhost:3000/favicon.ico
中查找您的收藏夹图标,因此这是需要的地方。尝试重写网址以为favicon.ico
路由提供/favicon.ico
。例如,如果您使用的是historyApiFallback,请执行以下操作:
historyApiFallback: {
rewrites: [
// shows favicon
{ from: /favicon.ico/, to: '[path/to/favicon]' }
]
}
关于javascript - Favicon无法显示,似乎是webpack的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35446947/