diff --git a/src/files.js b/src/files.js index 0b156bd0504..94c2d9d05d8 100644 --- a/src/files.js +++ b/src/files.js @@ -21,12 +21,9 @@ */ import { linkTo } from '@nextcloud/router' import { loadState } from '@nextcloud/initial-state' -import Vue from 'vue' +import { registerFileListHeaders } from '@nextcloud/files' import { logger } from './helpers/logger.js' -import { registerFileActionFallback } from './helpers/files.js' -import FilesSettings from './views/FilesSettings.vue' -import store from './store/index.js' __webpack_nonce__ = window.btoa(OC.requestToken) // eslint-disable-line __webpack_public_path__ = linkTo('text', 'js/') // eslint-disable-line @@ -34,13 +31,18 @@ __webpack_public_path__ = linkTo('text', 'js/') // eslint-disable-line const workspaceAvailable = loadState('text', 'workspace_available') const workspaceEnabled = loadState('text', 'workspace_enabled') -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener('DOMContentLoaded', async () => { if (typeof OCA.Viewer === 'undefined') { + const { registerFileActionFallback } = await import('./helpers/files.js') logger.error('Viewer app is not installed') registerFileActionFallback() } if (workspaceAvailable && OCA && OCA?.Files?.Settings) { + const { default: Vue } = await import('vue') + const { default: FilesSettings } = await import('./views/FilesSettings.vue') + const { default: store } = await import('./store/index.js') + Vue.prototype.t = window.t Vue.prototype.n = window.n Vue.prototype.OCA = window.OCA @@ -54,6 +56,10 @@ document.addEventListener('DOMContentLoaded', () => { })) } + if (workspaceAvailable) { + const { FilesWorkspaceHeader } = await import('./helpers/files.js') + registerFileListHeaders(FilesWorkspaceHeader) + } }) OCA.Text = { diff --git a/src/helpers/files.js b/src/helpers/files.js index 1985c2c6acb..a5ca85fddb3 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -27,7 +27,6 @@ import { loadState } from '@nextcloud/initial-state' import { getSharingToken } from './token.js' import { openMimetypes } from './mime.js' -import RichWorkspace from '../views/RichWorkspace.vue' import store from '../store/index.js' import { getCurrentUser } from '@nextcloud/auth' import { showSuccess, showError } from '@nextcloud/dialogs' @@ -211,7 +210,7 @@ export const FilesWorkspaceHeader = new Header({ return view.id === 'files' }, - render(el, folder, view) { + async render(el, folder, view) { if (vm) { // Enforce destroying of the old rendering and rerender as the FilesListHeader calls render on every folder change vm.$destroy() @@ -223,6 +222,8 @@ export const FilesWorkspaceHeader = new Header({ newWorkspaceCreated = false + const { default: RichWorkspace } = await import('./../views/RichWorkspace.vue') + import('vue').then((module) => { el.id = 'files-workspace-wrapper' diff --git a/src/viewer.js b/src/viewer.js index f66559b07ab..290cabe91d7 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -33,6 +33,7 @@ if (typeof OCA.Viewer === 'undefined') { OCA.Viewer.registerHandler({ id: 'text', mimes: [...openMimetypesMarkdown, ...openMimetypesPlainText], + // Would be good to be able to lazyload that component: ViewerComponent, group: null, theme: 'default', diff --git a/webpack.config.js b/webpack.config.js index 83164a1f2bd..0e1ce066064 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -45,11 +45,6 @@ webpackConfig.optimization.splitChunks.cacheGroups = { } } -// webpackConfig.resolve.modules = [ -// path.resolve(__dirname, 'node_modules'), -// 'node_modules' -// ] - // Fix Buffer issues webpackConfig.plugins.push(new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'], @@ -67,4 +62,15 @@ webpackRules.RULE_RAW_SVGS = { webpackConfig.module.rules = Object.values(webpackRules) +webpackConfig.optimization.splitChunks.minSize = 102400 + +webpackConfig.optimization.splitChunks.cacheGroups = { + mermaid: { + test(module) { + return module.resource && module.resource.includes(`${path.sep}node_modules${path.sep}mermaid`) + }, + name: 'mermaid', + }, +} + module.exports = webpackConfig