执行 npm run build
以后的 dist
目录的静态资源的文件名多会追加上 hash
值,好比: page1.f151b4d3.js
css
那若是不要 hash 呢,你只须要配置 vue.config.js 文件中的 filenameHashing
html
官方文档也提到了由于 html 也是咱们经过插件生成的,静态资源直接就 inject 进去的,因此,当 html 不是自动生成或者其余状况时候,就不能加 hash 了,能够配置 false。vue
filenameHashing: false
咱们看看源码实现:npm
首先它是 vue.config.js
的一个配置,在文件 cli-service/lib/options.js
中:函数
默认值是 true
ui
filenameHashing: true
先看 css
部分,在文件 cli-service/lib/config/css.js
中:插件
const filename = getAssetPath( options, `css/[name]${options.filenameHashing ? '.[contenthash:8]' : ''}.css` )
再看 js
部分,在文件 cli-service/lib/config/prod.js
code
const filename = getAssetPath( options, `js/[name]${isLegacyBundle ? `-legacy` : ``}${options.filenameHashing ? '.[contenthash:8]' : ''}.js` )
他们多依赖函数 getAssetPath
,在文件 util/getAssetPath.js
中定义了htm
const path = require('path') module.exports = function getAssetPath (options, filePath, placeAtRootIfRelative) { return options.assetsDir ? path.posix.join(options.assetsDir, filePath) : filePath }