Skip to content

Commit

Permalink
feat: use understandable file names for analyze mode (#4014)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
clarkdo authored and Atinux committed Sep 30, 2018
1 parent 8f06a18 commit 0393bf7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/builder/builder.js
Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions lib/builder/webpack/client.js
Expand Up @@ -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'),
Expand Down
18 changes: 12 additions & 6 deletions test/fixtures/with-config/with-config.test.js
Expand Up @@ -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)
})
Expand Down
5 changes: 5 additions & 0 deletions test/unit/with-config.test.js
Expand Up @@ -19,6 +19,11 @@ describe('with-config', () => {
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 () => {
const { html } = await nuxt.renderRoute('/')
expect(html).toContain('.global-css-selector')
Expand Down

0 comments on commit 0393bf7

Please sign in to comment.