From 8cb4188aa02c09b4b8071047b83f284f0f208982 Mon Sep 17 00:00:00 2001 From: William Chong Date: Thu, 15 Mar 2018 19:56:50 +0800 Subject: [PATCH 1/3] add support to vue-router redirect in extendRoutes --- lib/app/router.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/app/router.js b/lib/app/router.js index 2238ee8ef3..b49a436aa9 100644 --- a/lib/app/router.js +++ b/lib/app/router.js @@ -7,8 +7,9 @@ import Router from 'vue-router' route._name = '_' + hash(route.component) components.push({ _name: route._name, component: route.component, name: route.name, chunkName: route.chunkName }) res += tab + '{\n' - res += tab + '\tpath: ' + JSON.stringify(route.path) + ',\n' - res += tab + '\tcomponent: ' + (splitPages ? route._name : `() => ${route._name}.default || ${route._name}`) + res += tab + '\tpath: ' + JSON.stringify(route.path) + res += (route.component) ? ',\n\t' + tab + 'component: ' + (splitPages ? route._name : `() => ${route._name}.default || ${route._name}`) : '' + res += (route.redirect) ? ',\n\t' + tab + 'redirect: ' + JSON.stringify(route.redirect) : '' res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : '' res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t', components) + '\n\t' + tab + ']' : '' res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n') @@ -18,6 +19,7 @@ import Router from 'vue-router' const _components = [] const _routes = recursiveRoutes(router.routes, '\t\t', _components) %><%= uniqBy(_components, '_name').map((route) => { + if (!route.component) return '' const path = relativeToBuild(route.component) const chunkName = wChunk(route.chunkName) const name = route._name From 27e1423e247eefce445c2a44c6fb2ea2a9bdbecb Mon Sep 17 00:00:00 2001 From: William Chong Date: Thu, 15 Mar 2018 19:57:00 +0800 Subject: [PATCH 2/3] add test to extendRoutes redirect --- test/fixtures/with-config/nuxt.config.js | 4 ++++ test/with-config.test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 1997fd52ad..9814f16634 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -12,6 +12,10 @@ module.exports = { name: 'about-bis', path: '/about-bis', component: '~/pages/about.vue' + }, + { + path: '/redirect/about-bis', + redirect: '/about-bis' } ] } diff --git a/test/with-config.test.js b/test/with-config.test.js index 8900379d10..0db4283f0c 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -171,6 +171,21 @@ test.serial('/test/about-bis (added with extendRoutes)', async t => { t.true(html.includes('

About page

')) }) +test.serial('/test/redirect/about-bis (redirect with extendRoutes)', async t => { + const logSpy = await interceptLog() + const window = await nuxt.renderAndGetWindow(url('/test/redirect/about-bis')) + t.true(logSpy.calledOnce) + t.is(logSpy.args[0][0], 'Test plugin!') + release() + + const windowHref = window.location.href + t.true(windowHref.includes('/test/about-bis')) + + const html = window.document.body.innerHTML + t.true(html.includes('

Custom layout

')) + t.true(html.includes('

About page

')) +}) + test('Check stats.json generated by build.analyze', t => { const stats = require(resolve( __dirname, From 52068dcb880c7bc99e8c640d6893ee00566fa5c7 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Fri, 16 Mar 2018 17:59:03 +0800 Subject: [PATCH 3/3] refactor: use @nuxtjs/friendly-errors-webpack-plugin --- lib/builder/webpack/client.config.js | 2 +- package.json | 2 +- yarn.lock | 23 +++++++++-------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/builder/webpack/client.config.js b/lib/builder/webpack/client.config.js index 004e9628f4..1d874382af 100644 --- a/lib/builder/webpack/client.config.js +++ b/lib/builder/webpack/client.config.js @@ -3,7 +3,7 @@ const webpack = require('webpack') // const VueSSRClientPlugin = require('vue-server-renderer/client-plugin') const VueSSRClientPlugin = require('./plugins/vue/client') const HTMLPlugin = require('html-webpack-plugin') -const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin') +const FriendlyErrorsWebpackPlugin = require('@nuxtjs/friendly-errors-webpack-plugin') const StylishPlugin = require('webpack-stylish') const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') const { resolve } = require('path') diff --git a/package.json b/package.json index fbf722a4fe..360184227a 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "npm": ">=5.0.0" }, "dependencies": { + "@nuxtjs/friendly-errors-webpack-plugin": "^2.0.0", "@nuxtjs/youch": "^4.2.3", "ansi-html": "^0.0.7", "autoprefixer": "^8.1.0", @@ -75,7 +76,6 @@ "extract-text-webpack-plugin": "^4.0.0-beta.0", "file-loader": "^1.1.11", "fresh": "^0.5.2", - "friendly-errors-webpack-plugin": "^1.6.1", "fs-extra": "^5.0.0", "glob": "^7.1.2", "hash-sum": "^1.0.2", diff --git a/yarn.lock b/yarn.lock index e05331c921..6936bcfe8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -122,6 +122,15 @@ pretty-ms "^0.2.1" text-table "^0.2.0" +"@nuxtjs/friendly-errors-webpack-plugin@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@nuxtjs/friendly-errors-webpack-plugin/-/friendly-errors-webpack-plugin-2.0.0.tgz#70fb321c78362e2b4bce1d522ecdf7f87a4dacec" + dependencies: + chalk "^2.3.2" + error-stack-parser "^2.0.0" + string-width "^2.0.0" + strip-ansi "^4.0.0" + "@nuxtjs/youch@^4.2.3": version "4.2.3" resolved "https://registry.yarnpkg.com/@nuxtjs/youch/-/youch-4.2.3.tgz#36f8b22df5a0efaa81373109851e1d857aca6bed" @@ -3214,14 +3223,6 @@ fresh@0.5.2, fresh@^0.5.2: version "0.5.2" resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" -friendly-errors-webpack-plugin@^1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/friendly-errors-webpack-plugin/-/friendly-errors-webpack-plugin-1.6.1.tgz#e32781c4722f546a06a9b5d7a7cfa28520375d70" - dependencies: - chalk "^1.1.3" - error-stack-parser "^2.0.0" - string-length "^1.0.1" - from2@^2.1.0: version "2.3.0" resolved "https://registry.yarnpkg.com/from2/-/from2-2.3.0.tgz#8bfb5502bde4a4d36cfdeea007fcca21d7e382af" @@ -7047,12 +7048,6 @@ strict-uri-encode@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713" -string-length@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/string-length/-/string-length-1.0.1.tgz#56970fb1c38558e9e70b728bf3de269ac45adfac" - dependencies: - strip-ansi "^3.0.0" - string-width@^1.0.1, string-width@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"