From 06128e780564ff4fbfba63f5edf5f00c41d2a5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Sat, 18 Apr 2020 16:46:45 +0200 Subject: [PATCH] Async loading views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/router/index.js | 22 ++++++++++++++++++---- webpack.common.js | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 541aa05fd..e4fc69daa 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -20,15 +20,29 @@ * */ -import { generateUrl } from '@nextcloud/router' +import { generateUrl, generateFilePath } from '@nextcloud/router' import Router from 'vue-router' import Vue from 'vue' -import Albums from '../views/Albums' -import Timeline from '../views/Timeline' -import Tags from '../views/Tags' import isMapsInstalled from '../services/IsMapsInstalled' +import { getRequestToken } from '@nextcloud/auth' + +// CSP config for webpack dynamic chunk loading +// eslint-disable-next-line +__webpack_nonce__ = btoa(getRequestToken()) + +// Correct the root of the app for chunk loading +// OC.linkTo matches the apps folders +// OC.generateUrl ensure the index.php (or not) +// We do not want the index.php since we're loading files +// eslint-disable-next-line +__webpack_public_path__ = generateFilePath('photos', '', 'js/') + +const Albums = () => import('../views/Albums') +const Tags = () => import('../views/Tags') +const Timeline = () => import('../views/Timeline') + Vue.use(Router) let mapsPath = generateUrl('/apps/maps') diff --git a/webpack.common.js b/webpack.common.js index 4a3acbccd..d35c476cf 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -13,7 +13,7 @@ module.exports = { path: path.resolve(__dirname, './js'), publicPath: '/js/', filename: `${appName}.js`, - chunkFilename: '[name].js?v=[contenthash]', + chunkFilename: `${appName}.[name].js?v=[contenthash]`, }, module: { rules: [