remove SSR related files from generate artifacts

This commit is contained in:
Pooya Parsa 2017-08-18 16:14:47 +04:30
parent c5a5dac627
commit fbb6833400

View File

@ -1,5 +1,4 @@
import fs from 'fs'
import { copy, remove, writeFile, mkdirp } from 'fs-extra'
import { copy, remove, writeFile, mkdirp, removeSync, existsSync } from 'fs-extra'
import _ from 'lodash'
import { resolve, join, dirname, sep } from 'path'
import { minify } from 'html-minifier'
@ -49,7 +48,7 @@ export default class Generator extends Tapable {
try {
console.log('Generating routes') // eslint-disable-line no-console
generateRoutes = await promisifyRoute(this.options.generate.routes || [])
await this.applyPluginsAsync('generateRoutes', {generator: this, generateRoutes})
await this.applyPluginsAsync('generateRoutes', { generator: this, generateRoutes })
} catch (e) {
console.error('Could not resolve routes') // eslint-disable-line no-console
console.error(e) // eslint-disable-line no-console
@ -61,14 +60,14 @@ export default class Generator extends Tapable {
let routes = (this.options.router.mode === 'hash') ? ['/'] : flatRoutes(this.options.router.routes)
routes = this.decorateWithPayloads(routes, generateRoutes)
await this.applyPluginsAsync('generate', {generator: this, routes})
await this.applyPluginsAsync('generate', { generator: this, routes })
// Start generate process
while (routes.length) {
let n = 0
await Promise.all(routes.splice(0, this.options.generate.concurrency).map(async ({ route, payload }) => {
await waitFor(n++ * this.options.generate.interval)
await this.generateRoute({route, payload, errors})
await this.generateRoute({ route, payload, errors })
}))
}
@ -99,7 +98,7 @@ export default class Generator extends Tapable {
// Copy static and built files
/* istanbul ignore if */
if (fs.existsSync(this.generateRoutes)) {
if (existsSync(this.generateRoutes)) {
await copy(this.generateRoutes, this.distPath)
}
await copy(this.srcBuiltPath, this.distNuxtPath)
@ -109,6 +108,20 @@ export default class Generator extends Tapable {
const nojekyllPath = resolve(this.distPath, '.nojekyll')
writeFile(nojekyllPath, '')
// Cleanup SSR related files
const extraFiles = [
'index.spa.html',
'index.ssr.html',
'server-bundle.json',
'vue-ssr-client-manifest.json'
].map(file => resolve(this.distNuxtPath, file))
extraFiles.forEach(file => {
if (existsSync(file)) {
removeSync(file)
}
})
debug('Static & build files copied')
}
@ -133,7 +146,7 @@ export default class Generator extends Tapable {
return _.values(routeMap)
}
async generateRoute ({route, payload = {}, errors = []}) {
async generateRoute ({ route, payload = {}, errors = [] }) {
let html
try {