Skip to content

Commit

Permalink
feat: add filenameHashing option (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhvicey authored and yyx990803 committed Jul 30, 2018
1 parent d14b5cc commit ce7b394
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ module.exports = class Service {
resovledFrom = 'inline options'
}

// normlaize some options
// normalize some options
if (typeof resolved.baseUrl === 'string') {
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
}
Expand Down
20 changes: 16 additions & 4 deletions packages/@vue/cli-service/lib/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ module.exports = (api, options) => {
.loader('url-loader')
.options({
limit: inlineLimit,
name: getAssetPath(options, `img/[name].[hash:8].[ext]`)
name: getAssetPath(
options,
`img/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
)
})

// do not base64-inline SVGs.
Expand All @@ -93,7 +96,10 @@ module.exports = (api, options) => {
.use('file-loader')
.loader('file-loader')
.options({
name: getAssetPath(options, `img/[name].[hash:8].[ext]`)
name: getAssetPath(
options,
`img/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
)
})

webpackConfig.module
Expand All @@ -103,7 +109,10 @@ module.exports = (api, options) => {
.loader('url-loader')
.options({
limit: inlineLimit,
name: getAssetPath(options, `media/[name].[hash:8].[ext]`)
name: getAssetPath(
options,
`media/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
)
})

webpackConfig.module
Expand All @@ -113,7 +122,10 @@ module.exports = (api, options) => {
.loader('url-loader')
.options({
limit: inlineLimit,
name: getAssetPath(options, `fonts/[name].[hash:8].[ext]`)
name: getAssetPath(
options,
`fonts/[name]${options.filenameHashing ? '.[hash:8]' : ''}.[ext]`
)
})

// Other common pre-processors ---------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/config/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = (api, options) => {
const shouldExtract = isProd && extract !== false && !shadowMode
const filename = getAssetPath(
options,
`css/[name].[contenthash:8].css`,
`css/[name]${options.filenameHashing ? '.[contenthash:8]' : ''}.css`,
true /* placeAtRootIfRelative */
)
const extractOptions = Object.assign({
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/config/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (api, options) => {
const getAssetPath = require('../util/getAssetPath')
const filename = getAssetPath(
options,
`js/[name]${isLegacyBundle ? `-legacy` : ``}.[chunkhash:8].js`
`js/[name]${isLegacyBundle ? `-legacy` : ``}${options.filenameHashing ? '.[chunkhash:8]' : ''}.js`
)

webpackConfig
Expand Down
4 changes: 4 additions & 0 deletions packages/@vue/cli-service/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { createSchema, validate } = require('@vue/cli-shared-utils')
const schema = createSchema(joi => joi.object({
baseUrl: joi.string().allow(''),
outputDir: joi.string(),
filenameHashing: joi.boolean(),
assetsDir: joi.string(),
indexPath: joi.string(),
runtimeCompiler: joi.boolean(),
Expand Down Expand Up @@ -53,6 +54,9 @@ exports.defaults = () => ({
// where to output built files
outputDir: 'dist',

// whether filename will contain hash part
filenameHashing: true,

// where to put static assets (js/css/img/font/...)
assetsDir: '',

Expand Down

0 comments on commit ce7b394

Please sign in to comment.