Skip to content

Commit

Permalink
Lazy load components
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed May 21, 2023
1 parent 3c12fe0 commit 911966e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/components/Audios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@
</template>

<script>
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import '@skjnldsv/vue-plyr/dist/vue-plyr.css'
import logger from '../services/logger.js'

Vue.use(VuePlyr)
const VuePlyr = () => import(/* webpackChunkName: 'components' */'@skjnldsv/vue-plyr')

export default {
name: 'Audios',

components: {
VuePlyr,
},

computed: {
player() {
return this.$refs.plyr.player
Expand Down
10 changes: 7 additions & 3 deletions src/components/ImageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { basename, dirname, extname, join } from 'path'
import { emit } from '@nextcloud/event-bus'
import { showError, showSuccess } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import FilerobotImageEditor from 'filerobot-image-editor'
import logger from '../services/logger.js'
import translations from '../models/editorTranslations.js'
const { TABS, TOOLS } = FilerobotImageEditor
let TABS, TOOLS;
export default {
name: 'ImageEditor',
Expand Down Expand Up @@ -116,7 +115,12 @@ export default {
},
},
mounted() {
async mounted() {
// Lazy load the image editor
const FilerobotImageEditor = (await import(/* webpackChunkName: 'filerobot' */'filerobot-image-editor')).default
TABS = FilerobotImageEditor.TABS
TOOLS = FilerobotImageEditor.TOOLS
this.imageEditor = new FilerobotImageEditor(
this.$refs.editor,
this.config
Expand Down
10 changes: 6 additions & 4 deletions src/components/Videos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@
</template>

<script>
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import '@skjnldsv/vue-plyr/dist/vue-plyr.css'
import logger from '../services/logger.js'

const VuePlyr = () => import(/* webpackChunkName: 'components' */'@skjnldsv/vue-plyr')

const liveExt = ['jpg', 'jpeg', 'png']
const liveExtRegex = new RegExp(`\\.(${liveExt.join('|')})$`, 'i')

Vue.use(VuePlyr)

export default {
name: 'Videos',

components: {
VuePlyr,
},

computed: {
livePhoto() {
return this.fileList.find(file => {
Expand Down
11 changes: 8 additions & 3 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ import '@nextcloud/dialogs/dist/index.css'
import { showError } from '@nextcloud/dialogs'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink.js'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'

Expand All @@ -192,6 +189,14 @@ import Fullscreen from 'vue-material-design-icons/Fullscreen.vue'
import FullscreenExit from 'vue-material-design-icons/FullscreenExit.vue'
import Pencil from 'vue-material-design-icons/Pencil.vue'

// Dynamic loading
const NcModal = () => import(
/* webpackChunkName: 'components' */
/* webpackPrefetch: true */
'@nextcloud/vue/dist/Components/NcModal.js')
const NcActionLink = () => import(/* webpackChunkName: 'components' */'@nextcloud/vue/dist/Components/NcActionLink')
const NcActionButton = () => import(/* webpackChunkName: 'components' */'@nextcloud/vue/dist/Components/NcActionButton')

export default {
name: 'Viewer',

Expand Down
3 changes: 3 additions & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ webpackConfig.plugins.push(...[
// Add proper typescript support
webpackConfig.resolve.extensions = ['.ts', '.tsx', '.js', '.jsx', '.cjs', '.vue']

// Clean dist folder
webpackConfig.output.clean = true

export default webpackConfig

0 comments on commit 911966e

Please sign in to comment.