Skip to content

Commit

Permalink
Lazy load text-viewer and text-files
Browse files Browse the repository at this point in the history
+ Remove vendor bundling
+ Remove chunkIds declaration as it is already the default
+ Group mermaid chunks

Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge authored and juliushaertl committed Nov 25, 2023
1 parent b118adb commit cdc219f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
16 changes: 11 additions & 5 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@
*/
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

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
Expand All @@ -54,6 +56,10 @@ document.addEventListener('DOMContentLoaded', () => {
}))
}

if (workspaceAvailable) {
const { FilesWorkspaceHeader } = await import('./helpers/files.js')
registerFileListHeaders(FilesWorkspaceHeader)
}
})

OCA.Text = {
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand All @@ -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'

Expand Down
1 change: 1 addition & 0 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 11 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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

0 comments on commit cdc219f

Please sign in to comment.