Skip to content

Commit

Permalink
chore: improve bundle chunking
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 20, 2024
1 parent 29b0e39 commit 58f3c96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type MarkdownIt from 'markdown-it'

const md = ref<MarkdownIt>()
const md = shallowRef<MarkdownIt>()

let promise: Promise<void> | undefined

Expand Down
34 changes: 21 additions & 13 deletions packages/devtools/client/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import DevTools from '../src/module'

const resolver = createResolver(import.meta.url)

const packageBundles = [
'quicktype-core',
'shiki',
]
const packageBundles = {
'shiki': ['shiki', '@shikijs'],
'quicktype-core': ['quicktype-core'],
'json-editor-vue': ['json-editor-vue', 'ajv', 'vanilla-picker', 'vanilla-jsoneditor'],
'xterm': ['xterm', '@xterm'],
'vis': ['vis-data', 'vis-network'],
'unocss': ['@unocss', 'unocss'],
'markdown-it': ['markdown-it'],
}

export default defineNuxtConfig({
modules: [
Expand Down Expand Up @@ -84,18 +89,21 @@ export default defineNuxtConfig({
target: 'esnext',
rollupOptions: {
output: {
chunkFileNames(chunkInfo) {
const kebabName = chunkInfo.name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
return `_nuxt/${kebabName}-[hash].js`
},
assetFileNames(assetInfo) {
const kebabName = (assetInfo.name || '').replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
return `_nuxt/${kebabName}-[hash][extname]`
},
manualChunks(id) {
const pkg = packageBundles.find(pkg => id.includes(`node_modules/${pkg}`))
if (pkg) {
return pkg
for (const bundle of Object.entries(packageBundles)) {
if (bundle[1].some(pkg => id.includes(`node_modules/${pkg}/`)))
return `vendor/${bundle[0]}`
}

// if (id.includes('.nuxt/routes'))
// return 'routes'

// if (id.includes('.nuxt'))
// console.log(id)
},
hashCharacters: 'base36',
},
},
},
Expand Down

0 comments on commit 58f3c96

Please sign in to comment.