From 06073697f49d8f347aa238869ef50fa525ec4c43 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 27 Mar 2020 14:08:48 +0100 Subject: [PATCH] fix(vue-app): sanitize layouts after resolve for `splitChunks.layout` (#7139) --- packages/vue-app/template/App.js | 8 ++++++-- test/fixtures/basic/nuxt.config.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vue-app/template/App.js b/packages/vue-app/template/App.js index 2838dac26e..ce304f644c 100644 --- a/packages/vue-app/template/App.js +++ b/packages/vue-app/template/App.js @@ -18,15 +18,19 @@ import '<%= relativeToBuild(resolvePath(c.src || c, { isStyle: true })) %>' <% if (features.layouts) { %> <%= Object.keys(layouts).map((key) => { if (splitChunks.layouts) { - return `const _${hash(key)} = () => import('${layouts[key]}' /* webpackChunkName: "${wChunk('layouts/' + key)}" */).then(m => m.default || m)` + return `const _${hash(key)} = () => import('${layouts[key]}' /* webpackChunkName: "${wChunk('layouts/' + key)}" */).then(m => sanitizeComponent(m.default || m))` } else { return `import _${hash(key)} from '${layouts[key]}'` } }).join('\n') %> +<% if (splitChunks.layouts) { %> +let resolvedLayouts = {} +const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`).join(',') %> }<%= isTest ? '// eslint-disable-line' : '' %> +<% } else { %> const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": sanitizeComponent(_${hash(key)})`).join(',') %> }<%= isTest ? '// eslint-disable-line' : '' %> +<% } %> -<% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %> <% } %> export default { diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index 5e47058d45..652c45d196 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -81,6 +81,9 @@ export default { scopeHoisting: true, publicPath: '', followSymlinks: true, + splitChunks: { + layouts: true + }, postcss: { preset: { features: {