Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert production js chunk names #8012

Merged
merged 6 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/config/src/config/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default () => ({
serverURLPolyfill: 'url',
filenames: {
// { isDev, isClient, isServer }
app: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[name].[contenthash:7]${isModern ? '.modern' : ''}.js`,
chunk: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[name].[contenthash:7]${isModern ? '.modern' : ''}.js`,
app: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[contenthash:7]${isModern ? '.modern' : ''}.js`,
chunk: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[contenthash:7]${isModern ? '.modern' : ''}.js`,
css: ({ isDev }) => isDev ? '[name].css' : '[name].[contenthash:7].css',
img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]',
font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]',
Expand Down Expand Up @@ -62,7 +62,6 @@ export default () => ({
minimizer: undefined,
splitChunks: {
chunks: 'all',
automaticNameDelimiter: '/',
cacheGroups: {}
}
},
Expand Down
1 change: 0 additions & 1 deletion packages/config/test/__snapshots__/options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ Object {
"minimizer": undefined,
"runtimeChunk": "single",
"splitChunks": Object {
"automaticNameDelimiter": "/",
"cacheGroups": Object {},
"chunks": "all",
},
Expand Down
2 changes: 0 additions & 2 deletions packages/config/test/config/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Object {
"minimizer": undefined,
"runtimeChunk": "single",
"splitChunks": Object {
"automaticNameDelimiter": "/",
"cacheGroups": Object {},
"chunks": "all",
},
Expand Down Expand Up @@ -465,7 +464,6 @@ Object {
"minimizer": undefined,
"runtimeChunk": "single",
"splitChunks": Object {
"automaticNameDelimiter": "/",
"cacheGroups": Object {},
"chunks": "all",
},
Expand Down
4 changes: 2 additions & 2 deletions packages/config/test/config/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('config: build', () => {
test('should return prod filenames', () => {
const { filenames } = buildConfig()
const env = { isDev: false }
expect(filenames.app(env)).toEqual('[name].[contenthash:7].js')
expect(filenames.chunk(env)).toEqual('[name].[contenthash:7].js')
expect(filenames.app(env)).toEqual('[contenthash:7].js')
expect(filenames.chunk(env)).toEqual('[contenthash:7].js')
expect(filenames.css(env)).toEqual('[name].[contenthash:7].css')
expect(filenames.img(env)).toEqual('img/[name].[contenthash:7].[ext]')
expect(filenames.font(env)).toEqual('fonts/[name].[contenthash:7].[ext]')
Expand Down
3 changes: 3 additions & 0 deletions packages/webpack/src/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export default class WebpackBaseConfig {
consola.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`)
}
}
if (this.buildContext.buildOptions.analyze && !fileName.includes('[name]')) {
fileName = '[name].' + fileName
}
return fileName
}

Expand Down
38 changes: 1 addition & 37 deletions packages/webpack/src/config/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,47 +66,11 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
cacheGroups.commons = {
test: /node_modules[\\/](vue|vue-loader|vue-router|vuex|vue-meta|core-js|@babel\/runtime|axios|webpack|setimmediate|timers-browserify|process|regenerator-runtime|cookie|js-cookie|is-buffer|dotprop|nuxt\.js)[\\/]/,
chunks: 'all',
name: 'vendors/commons',
name: true,
priority: 10
}
}

if (!this.dev && splitChunks.name === undefined) {
const nameMap = { default: 'commons' }
splitChunks.name = (_module, chunks, cacheGroup) => {
// Map chunks to names
const names = chunks
.map(c => c.name || '')
.map(name => name
.replace(/[/\\]/g, '.')
.replace(/_/g, '')
.replace('pages.', '')
)
.filter(Boolean)
.sort()

// Fallback to webpack chunk name or generated cache group key
if (names.length < 2) {
return chunks[0].name
}

// Use compact name for concatinated modules
let compactName = names.join('~')
if (compactName.length > 32) {
compactName = hash(compactName)
}
const prefix = nameMap[cacheGroup || 'default'] || cacheGroup
return prefix + '/' + compactName
}

// Enforce name for all groups
for (const group of Object.values(cacheGroups)) {
if (group.name === undefined) {
group.name = true
}
}
}

return optimization
}

Expand Down