feat: use understandable file names for analyze mode (#4014)

* feat: use understandable file names for analyze mode

* test: asset name for analyze mode

* refactor: add warning message for analyze mode

* refactor: move analyze warning to builder

* test: analyze warning message
This commit is contained in:
Clark Du 2018-09-30 17:11:20 +01:00 committed by Sébastien Chopin
parent 8f06a187db
commit 0393bf781c
4 changed files with 36 additions and 6 deletions

View File

@ -59,6 +59,15 @@ export default class Builder {
this.mfs = new MFS() this.mfs = new MFS()
} }
if (this.options.build.analyze) {
this.nuxt.hook('build:done', () => {
consola.warn({
message: 'Notice: Please do not deploy bundles built with analyze mode, it\'s only for analyzing purpose.',
badge: true
})
})
}
// if(!this.options.dev) { // if(!this.options.dev) {
// TODO: enable again when unsafe concern resolved.(common/options.js:42) // TODO: enable again when unsafe concern resolved.(common/options.js:42)
// this.nuxt.hook('build:done', () => this.generateConfig()) // this.nuxt.hook('build:done', () => this.generateConfig())

View File

@ -15,6 +15,16 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
super(builder, { name: 'client', isServer: false }) super(builder, { name: 'client', isServer: false })
} }
getFileName(...args) {
if (this.options.build.analyze) {
const key = args[0]
if (['app', 'chunk'].includes(key)) {
return '[name].js'
}
}
return super.getFileName(...args)
}
env() { env() {
return Object.assign(super.env(), { return Object.assign(super.env(), {
'process.env.VUE_ENV': JSON.stringify('client'), 'process.env.VUE_ENV': JSON.stringify('client'),

View File

@ -14,13 +14,19 @@ const hooks = [
describe('with-config', () => { describe('with-config', () => {
buildFixture('with-config', () => { buildFixture('with-config', () => {
expect(consola.warn).toHaveBeenCalledTimes(1) expect(consola.warn).toHaveBeenCalledTimes(2)
expect(consola.fatal).toHaveBeenCalledTimes(0) expect(consola.fatal).toHaveBeenCalledTimes(0)
expect(consola.warn.mock.calls[0]).toMatchObject([{ expect(consola.warn.mock.calls).toMatchObject([
[{
message: 'Found 2 plugins that match the configuration, suggest to specify extension:', message: 'Found 2 plugins that match the configuration, suggest to specify extension:',
additional: expect.stringContaining('plugins/test.json'), additional: expect.stringContaining('plugins/test.json'),
badge: true badge: true
}]) }],
[{
message: 'Notice: Please do not deploy bundles built with analyze mode, it\'s only for analyzing purpose.',
badge: true
}]
])
expect(customCompressionMiddlewareFunctionName).toBe('damn') expect(customCompressionMiddlewareFunctionName).toBe('damn')
}, hooks) }, hooks)
}) })

View File

@ -19,6 +19,11 @@ describe('with-config', () => {
expect(html.includes('<h1>I have custom configurations</h1>')).toBe(true) expect(html.includes('<h1>I have custom configurations</h1>')).toBe(true)
}) })
test('/ (asset name for analyze mode)', async () => {
const { html } = await nuxt.renderRoute('/')
expect(html).toContain('<script src="/test/orion/app.js"')
})
test.skip('/ (global styles inlined)', async () => { test.skip('/ (global styles inlined)', async () => {
const { html } = await nuxt.renderRoute('/') const { html } = await nuxt.renderRoute('/')
expect(html).toContain('.global-css-selector') expect(html).toContain('.global-css-selector')