From 14fe6792ae849e9a7ab854cf04cbff703f495ccb Mon Sep 17 00:00:00 2001 From: Clark Du Date: Tue, 4 Dec 2018 12:11:18 +0000 Subject: [PATCH] feat: check modern build file in modern mode (#4467) [skip release] --- packages/vue-renderer/src/renderer.js | 14 ++++++++++---- test/unit/renderer.test.js | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/vue-renderer/src/renderer.js b/packages/vue-renderer/src/renderer.js index 9c0a4f5d0c..06835e75c9 100644 --- a/packages/vue-renderer/src/renderer.js +++ b/packages/vue-renderer/src/renderer.js @@ -103,10 +103,16 @@ export default class VueRenderer { await this.loadResources(fs) // Verify - if (!this.isReady && this.context.options._start) { - throw new Error( - 'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.' - ) + if (this.context.options._start) { + if (!this.isReady) { + throw new Error( + 'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.' + ) + } else if (this.context.options.modern && !this.context.resources.modernManifest) { + throw new Error( + 'No modern build files found. Use either `nuxt build --modern` or `modern` option to build modern files.' + ) + } } } else { // Development: Listen on build:resources hook diff --git a/test/unit/renderer.test.js b/test/unit/renderer.test.js index 8c2ebf8444..2495fa7269 100644 --- a/test/unit/renderer.test.js +++ b/test/unit/renderer.test.js @@ -1,9 +1,15 @@ +import path from 'path' import consola from 'consola' import { Nuxt } from '../utils' const NO_BUILD_MSG = 'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.' +const NO_MODERN_BUILD_MSG = 'No modern build files found. Use either `nuxt build --modern` or `modern` option to build modern files.' describe('renderer', () => { + afterEach(() => { + consola.fatal.mockClear() + }) + test('detect no-build (Universal)', async () => { const nuxt = new Nuxt({ _start: true, @@ -27,4 +33,16 @@ describe('renderer', () => { await expect(nuxt.renderer.renderer.isReady).toBe(false) expect(consola.fatal).toHaveBeenCalledWith(new Error(NO_BUILD_MSG)) }) + test('detect no-modern-build', async () => { + const nuxt = new Nuxt({ + _start: true, + mode: 'universal', + modern: 'client', + dev: false, + buildDir: path.resolve(__dirname, '..', 'fixtures', 'empty', '.nuxt') + }) + await nuxt.ready() + await expect(nuxt.renderer.renderer.isReady).toBe(true) + expect(consola.fatal).toHaveBeenCalledWith(new Error(NO_MODERN_BUILD_MSG)) + }) })