Skip to content

Commit

Permalink
fix: improve chunking
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 27, 2024
1 parent af6e9b4 commit b37665d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 4 additions & 3 deletions packages/client/builtin/Monaco.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ Learn more: https://sli.dev/guide/syntax.html#monaco-editor
-->

<script setup lang="ts">
import * as monaco from 'monaco-editor'
import type * as monaco from 'monaco-editor'
import { computed, nextTick, onMounted, ref } from 'vue'
import { debounce } from '@antfu/utils'
import lz from 'lz-string'
import setup from '../setup/monaco'
import { makeId } from '../logic/utils'
const props = withDefaults(defineProps<{
Expand Down Expand Up @@ -67,7 +66,9 @@ const height = computed(() => {
})
onMounted(async () => {
const { ata } = await setup()
// Lazy load monaco, so it will be bundled in async chunk
const { default: setup } = await import('../setup/monaco')
const { ata, monaco } = await setup()
const model = monaco.editor.createModel(code, lang, monaco.Uri.parse(`file:///${makeId()}.${ext}`))
const commonOptions = {
automaticLayout: true,
Expand Down
1 change: 0 additions & 1 deletion packages/client/setup/monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { isDark } from '../logic/dark'
import configs from '#slidev/configs'

/* __imports__ */

window.MonacoEnvironment = {
getWorker(_, label) {
if (label === 'json')
Expand Down
13 changes: 5 additions & 8 deletions packages/slidev/node/plugins/extendConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ export function createConfigPlugin(options: ResolvedSlidevOptions): Plugin {
rollupOptions: {
output: {
chunkFileNames(chunkInfo) {
const DEFAULT = '[name]-[hash].js'
const DEFAULT = 'assets/[name]-[hash].js'

// Already handled in manualChunks
if (chunkInfo.name.includes('/') || chunkInfo.name === 'entry')
if (chunkInfo.name.includes('/'))
return DEFAULT

// Over 60% of the chunk is slidev client code, we put it into slidev chunk
if (chunkInfo.moduleIds.filter(i => isSlidevClient(i)).length > chunkInfo.moduleIds.length * 0.6)
return 'slidev/[name]-[hash].js'
return 'assets/slidev/[name]-[hash].js'

// Monaco Editor
if (chunkInfo.moduleIds.filter(i => i.includes('/monaco-editor/')).length > chunkInfo.moduleIds.length * 0.6)
return 'monaco/[name]-[hash].js'
if (chunkInfo.moduleIds.filter(i => i.match(/\/monaco-editor(-core)?\//)).length > chunkInfo.moduleIds.length * 0.6)
return 'assets/monaco/[name]-[hash].js'

return DEFAULT
},
Expand All @@ -93,9 +93,6 @@ export function createConfigPlugin(options: ResolvedSlidevOptions): Plugin {
return `modules/shiki`
if (id.startsWith('~icons/'))
return 'modules/unplugin-icons'
if (id.includes('/client/main.ts'))
return 'entry'

// It seems that moving slides out will breaks the production build
// Would need to find a better way to handle this
// const slideMatch = id.match(/\/@slidev\/slides\/(\d+)/)
Expand Down

0 comments on commit b37665d

Please sign in to comment.