Skip to content

Commit

Permalink
fix: generate failure (#5007)
Browse files Browse the repository at this point in the history
  • Loading branch information
karakum authored and clarkdo committed Feb 13, 2019
1 parent ad6a8cd commit bcd672f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/webpack/src/plugins/vue/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate, isJS } from './util'
import { validate, isJS, extractQueryPartJS } from './util'

export default class VueSSRServerPlugin {
constructor(options = {}) {
Expand Down Expand Up @@ -44,7 +44,12 @@ export default class VueSSRServerPlugin {

stats.assets.forEach((asset) => {
if (isJS(asset.name)) {
bundle.files[asset.name] = asset.name
const queryPart = extractQueryPartJS(asset.name)
if (queryPart !== undefined) {
bundle.files[asset.name] = asset.name.replace(queryPart, '')
} else {
bundle.files[asset.name] = asset.name
}
} else if (asset.name.match(/\.js\.map$/)) {
bundle.maps[asset.name.replace(/\.map$/, '')] = asset.name
} else {
Expand Down
6 changes: 5 additions & 1 deletion packages/webpack/src/plugins/vue/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const validate = (compiler) => {
}
}

export const isJS = file => /\.js(\?[^.]+)?$/.test(file)
const isJSRegExp = /\.js(\?[^.]+)?$/

export const isJS = file => isJSRegExp.test(file)

export const extractQueryPartJS = file => isJSRegExp.exec(file)[1]

export const isCSS = file => /\.css(\?[^.]+)?$/.test(file)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { buildFixture } from '../../utils/build'

buildFixture('filenames-query-part')
8 changes: 8 additions & 0 deletions test/fixtures/filenames-query-part/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
build: {
filenames: {
app: '[name].js?v=[contenthash]',
chunk: '[name].js?v=[contenthash]'
}
}
}
5 changes: 5 additions & 0 deletions test/fixtures/filenames-query-part/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<h1>Chunks with version in query part</h1>
</div>
</template>
53 changes: 53 additions & 0 deletions test/unit/filenames-query-part.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { resolve } from 'path'
import { existsSync, readFileSync } from 'fs'
import { getPort, loadFixture, Nuxt } from '../utils'

let port

let nuxt = null

expect.extend({
toFileExist(file) {
if (existsSync(file)) {
return {
message: () => `expected '${file}' not exist`,
pass: true
}
} else {
return {
message: () => `expected '${file}' exist`,
pass: false
}
}
}
})

describe('build filenames with query part', () => {
beforeAll(async () => {
const config = await loadFixture('filenames-query-part')
nuxt = new Nuxt(config)
port = await getPort()
await nuxt.server.listen(port, 'localhost')
})

test('server manifest files exist', () => {
const manifest = JSON.parse(readFileSync(resolve(__dirname, '..', 'fixtures/filenames-query-part/.nuxt/dist/server/server.manifest.json'), 'utf8'))
expect(manifest).toMatchObject({
files: expect.any(Object)
})
for (const file in manifest.files) {
expect(resolve(__dirname, '..', `fixtures/filenames-query-part/.nuxt/dist/server/${manifest.files[file]}`)).toFileExist()
}
})

test("render / without error 'Cannot find module'", async () => {
await expect(nuxt.server.renderRoute('/')).resolves.toMatchObject({
html: expect.stringContaining('<h1>Chunks with version in query part</h1>')
})
})

// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
})
})

0 comments on commit bcd672f

Please sign in to comment.