Skip to content

Commit 92473e9

Browse files
committed
refactor: extract asset path logic
1 parent ce7b394 commit 92473e9

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ module.exports = (api, options) => {
55
const getAssetPath = require('../util/getAssetPath')
66
const inlineLimit = 4096
77

8+
const genAssetSubPath = dir => {
9+
return getAssetPath(
10+
options,
11+
`${dir}/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
12+
)
13+
}
14+
815
webpackConfig
916
.mode('development')
1017
.context(api.service.context)
@@ -82,10 +89,7 @@ module.exports = (api, options) => {
8289
.loader('url-loader')
8390
.options({
8491
limit: inlineLimit,
85-
name: getAssetPath(
86-
options,
87-
`img/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
88-
)
92+
name: genAssetSubPath('img')
8993
})
9094

9195
// do not base64-inline SVGs.
@@ -96,10 +100,7 @@ module.exports = (api, options) => {
96100
.use('file-loader')
97101
.loader('file-loader')
98102
.options({
99-
name: getAssetPath(
100-
options,
101-
`img/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
102-
)
103+
name: genAssetSubPath('img')
103104
})
104105

105106
webpackConfig.module
@@ -109,10 +110,7 @@ module.exports = (api, options) => {
109110
.loader('url-loader')
110111
.options({
111112
limit: inlineLimit,
112-
name: getAssetPath(
113-
options,
114-
`media/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
115-
)
113+
name: genAssetSubPath('media')
116114
})
117115

118116
webpackConfig.module
@@ -122,10 +120,7 @@ module.exports = (api, options) => {
122120
.loader('url-loader')
123121
.options({
124122
limit: inlineLimit,
125-
name: getAssetPath(
126-
options,
127-
`fonts/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
128-
)
123+
name: genAssetSubPath('fonts')
129124
})
130125

131126
// Other common pre-processors ---------------------------------------------

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ 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(),
76
assetsDir: joi.string(),
87
indexPath: joi.string(),
8+
filenameHashing: joi.boolean(),
99
runtimeCompiler: joi.boolean(),
1010
transpileDependencies: joi.array(),
1111
productionSourceMap: joi.boolean(),
@@ -54,15 +54,15 @@ exports.defaults = () => ({
5454
// where to output built files
5555
outputDir: 'dist',
5656

57-
// whether filename will contain hash part
58-
filenameHashing: true,
59-
6057
// where to put static assets (js/css/img/font/...)
6158
assetsDir: '',
6259

6360
// filename for index.html (relative to outputDir)
6461
indexPath: 'index.html',
6562

63+
// whether filename will contain hash part
64+
filenameHashing: true,
65+
6666
// boolean, use full build?
6767
runtimeCompiler: false,
6868

0 commit comments

Comments
 (0)