diff --git a/lib/builder/webpack/base.js b/lib/builder/webpack/base.js index dbda780db4..2ca6ece17b 100644 --- a/lib/builder/webpack/base.js +++ b/lib/builder/webpack/base.js @@ -46,6 +46,10 @@ export default class WebpackBaseConfig { getFileName(name) { let fileName = this.options.build.filenames[name] + if (typeof fileName === 'function') { + fileName = fileName(name) + } + // Don't use hashes when watching // https://github.com/webpack/webpack/issues/1914#issuecomment-174171709 if (this.options.dev) { diff --git a/test/unit/basic.dev.test.js b/test/unit/basic.dev.test.js index b723e31c32..b40e83b6a3 100644 --- a/test/unit/basic.dev.test.js +++ b/test/unit/basic.dev.test.js @@ -6,6 +6,7 @@ const url = route => 'http://localhost:' + port + route let nuxt = null let builder = null let transpile = null +let appFileName = null describe('basic dev', () => { beforeAll(async () => { @@ -14,14 +15,20 @@ describe('basic dev', () => { debug: true, buildDir: '.nuxt-dev', build: { + filenames: { + app: () => { + return 'test-app.[contenthash].js' + } + }, transpile: [ 'vue\\.test\\.js', /vue-test/ ], - extend({ module: { rules } }, { isClient }) { + extend({ module: { rules }, output: { filename } }, { isClient }) { if (isClient) { const babelLoader = rules.find(loader => loader.test.test('.jsx')) transpile = file => !babelLoader.exclude(file) + appFileName = filename } } } @@ -45,6 +52,10 @@ describe('basic dev', () => { expect(transpile('node_modules/test.vue.js')).toBe(true) }) + test('Config: build.filenames as function', () => { + expect(appFileName).toBe('test-app.js') + }) + test('/stateless', async () => { const window = await nuxt.renderAndGetWindow(url('/stateless')) const html = window.document.body.innerHTML