我需要使用webpack加载ico和svg文件。但是,文件名被转换为哈希数字,因此HTML文件无法找到这些资源并生成404错误。
我需要加载器对资源文件名进行哈希处理,并同时在HTML文件中将文件名更改为哈希名称。我该如何做到这一点?
以下是用于显示一个SVG和一个图标的HTML代码。
以下是用于显示一个SVG和一个图标的HTML代码。
<object type="image/svg+xml" data="spider-web.svg">
Your browser does not support SVG
</object>
<img src="favicon.ico" alt="">
以下是webpack配置文件:
'use strict';
// webpack.config.js
var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var entryBasePath = __dirname;
var outputBasePath = __dirname + '/dist';
module.exports = {
context: entryBasePath,
entry:{
app: ['webpack/hot/dev-server', './appEntry.js']
},
output: {
path: outputBasePath,
filename: './bundle.js',
sourceMapFilename: '[file].map' // set source map output name rule
},
devtool: 'source-map', // enable source map
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({template: 'index.html'}),
// new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}})
],
module: {
loaders: [
{test: /\.scss$/, loader: 'style!css!sass'},
{test: /\.css$/, loader: 'style!css'},
{test: /\.(html|ico)(\?[\s\S]+)?$/, loader: 'raw'},
{
test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url?limit=10000"
},
{
test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
loader: 'file'
},
{ test: /bootstrap-sass\/assets\/javascripts\//, loader: 'imports?jQuery=jquery' },
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }
]
}
}
{ test: /\.(svg)$/i, loader: 'file-loader', options: { name: 'icons/[name].[ext]' } },
- FloppyNotFound