Skip to content

Commit ce7b394

Browse files
yhviceyyyx990803
authored andcommitted
feat: add filenameHashing option (vuejs#1980)
1 parent d14b5cc commit ce7b394

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

packages/@vue/cli-service/lib/Service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ module.exports = class Service {
297297
resovledFrom = 'inline options'
298298
}
299299

300-
// normlaize some options
300+
// normalize some options
301301
if (typeof resolved.baseUrl === 'string') {
302302
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
303303
}

packages/@vue/cli-service/lib/config/base.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ module.exports = (api, options) => {
8282
.loader('url-loader')
8383
.options({
8484
limit: inlineLimit,
85-
name: getAssetPath(options, `img/[name].[hash:8].[ext]`)
85+
name: getAssetPath(
86+
options,
87+
`img/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
88+
)
8689
})
8790

8891
// do not base64-inline SVGs.
@@ -93,7 +96,10 @@ module.exports = (api, options) => {
9396
.use('file-loader')
9497
.loader('file-loader')
9598
.options({
96-
name: getAssetPath(options, `img/[name].[hash:8].[ext]`)
99+
name: getAssetPath(
100+
options,
101+
`img/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
102+
)
97103
})
98104

99105
webpackConfig.module
@@ -103,7 +109,10 @@ module.exports = (api, options) => {
103109
.loader('url-loader')
104110
.options({
105111
limit: inlineLimit,
106-
name: getAssetPath(options, `media/[name].[hash:8].[ext]`)
112+
name: getAssetPath(
113+
options,
114+
`media/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
115+
)
107116
})
108117

109118
webpackConfig.module
@@ -113,7 +122,10 @@ module.exports = (api, options) => {
113122
.loader('url-loader')
114123
.options({
115124
limit: inlineLimit,
116-
name: getAssetPath(options, `fonts/[name].[hash:8].[ext]`)
125+
name: getAssetPath(
126+
options,
127+
`fonts/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
128+
)
117129
})
118130

119131
// Other common pre-processors ---------------------------------------------

packages/@vue/cli-service/lib/config/css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = (api, options) => {
2525
const shouldExtract = isProd && extract !== false && !shadowMode
2626
const filename = getAssetPath(
2727
options,
28-
`css/[name].[contenthash:8].css`,
28+
`css/[name]${options.filenameHashing ? '.[contenthash:8]' : ''}.css`,
2929
true /* placeAtRootIfRelative */
3030
)
3131
const extractOptions = Object.assign({

packages/@vue/cli-service/lib/config/prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = (api, options) => {
55
const getAssetPath = require('../util/getAssetPath')
66
const filename = getAssetPath(
77
options,
8-
`js/[name]${isLegacyBundle ? `-legacy` : ``}.[chunkhash:8].js`
8+
`js/[name]${isLegacyBundle ? `-legacy` : ``}${options.filenameHashing ? '.[chunkhash:8]' : ''}.js`
99
)
1010

1111
webpackConfig

packages/@vue/cli-service/lib/options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { createSchema, validate } = require('@vue/cli-shared-utils')
33
const schema = createSchema(joi => joi.object({
44
baseUrl: joi.string().allow(''),
55
outputDir: joi.string(),
6+
filenameHashing: joi.boolean(),
67
assetsDir: joi.string(),
78
indexPath: joi.string(),
89
runtimeCompiler: joi.boolean(),
@@ -53,6 +54,9 @@ exports.defaults = () => ({
5354
// where to output built files
5455
outputDir: 'dist',
5556

57+
// whether filename will contain hash part
58+
filenameHashing: true,
59+
5660
// where to put static assets (js/css/img/font/...)
5761
assetsDir: '',
5862

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy