这里的hash主要从两个方面来说。一个是webpack生成的hash,另一个是页面链接中的hash,如:http://localhost:8080/ywbk.html#restaurant
中的#restaurant
。后者在单页面应用的路由处理中经常用到。
webpack中的hash
webapck每次构建都会生成一个新的hash(主要用于生产环境)。
它的作用就是用来标记构建生成的状态,通常使用的过程中,会将它注入到构建输出(生成)的文件名中。
在webpack.config.js
文件中的位置如下:
...
output: {
path: path.resolve(__dirname, 'dist/'),
filename: isDev ? 'assets/js/[name].js' : 'assets/js/[name].[contenthash].js',
publicPath: isDev ? config.devUrl : config.deployUrl
},
module: {
rules: [
...
{
include: path.resolve(__dirname, 'assets/imgs/other/'),
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: isDev ? '[name].[ext]' : '[name].[hash].[ext]',
outputPath: 'assets/imgs/'