diff --git a/lib/builder/builder.js b/lib/builder/builder.js index b1190f638a..bafaccfa7d 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -59,6 +59,15 @@ export default class Builder { 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) { // TODO: enable again when unsafe concern resolved.(common/options.js:42) // this.nuxt.hook('build:done', () => this.generateConfig()) diff --git a/lib/builder/webpack/client.js b/lib/builder/webpack/client.js index 0f0cc9bc91..775862ff36 100644 --- a/lib/builder/webpack/client.js +++ b/lib/builder/webpack/client.js @@ -15,6 +15,16 @@ export default class WebpackClientConfig extends WebpackBaseConfig { 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() { return Object.assign(super.env(), { 'process.env.VUE_ENV': JSON.stringify('client'), diff --git a/test/fixtures/with-config/with-config.test.js b/test/fixtures/with-config/with-config.test.js index 3de1cbe586..d16e0f0a1e 100644 --- a/test/fixtures/with-config/with-config.test.js +++ b/test/fixtures/with-config/with-config.test.js @@ -14,13 +14,19 @@ const hooks = [ describe('with-config', () => { buildFixture('with-config', () => { - expect(consola.warn).toHaveBeenCalledTimes(1) + expect(consola.warn).toHaveBeenCalledTimes(2) expect(consola.fatal).toHaveBeenCalledTimes(0) - expect(consola.warn.mock.calls[0]).toMatchObject([{ - message: 'Found 2 plugins that match the configuration, suggest to specify extension:', - additional: expect.stringContaining('plugins/test.json'), - badge: true - }]) + expect(consola.warn.mock.calls).toMatchObject([ + [{ + message: 'Found 2 plugins that match the configuration, suggest to specify extension:', + additional: expect.stringContaining('plugins/test.json'), + 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') }, hooks) }) diff --git a/test/unit/with-config.test.js b/test/unit/with-config.test.js index 76659d6372..2ad6726adf 100644 --- a/test/unit/with-config.test.js +++ b/test/unit/with-config.test.js @@ -19,6 +19,11 @@ describe('with-config', () => { expect(html.includes('

I have custom configurations

')).toBe(true) }) + test('/ (asset name for analyze mode)', async () => { + const { html } = await nuxt.renderRoute('/') + expect(html).toContain('