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

feat: support functional filenames #3787

Merged
merged 1 commit into from Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions lib/builder/webpack/base.js
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion test/unit/basic.dev.test.js
Expand Up @@ -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 () => {
Expand All @@ -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
}
}
}
Expand All @@ -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
Expand Down