Skip to content

Commit

Permalink
Merge pull request #29 from misaon/patch-1
Browse files Browse the repository at this point in the history
Separating Swiper into chunks from entry bundle
  • Loading branch information
cpreston321 committed Feb 6, 2023
2 parents 8d6d61d + 678a962 commit 9719628
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as swiper from 'swiper'
import {
defineNuxtModule,
addPluginTemplate,
addImports
addImports,
extendViteConfig
} from '@nuxt/kit'
import { name, version } from '../package.json'

Expand Down Expand Up @@ -36,6 +37,23 @@ export default defineNuxtModule<SwiperModuleOptions>({
}
]

// Add Manual Chunks for Swiper for Vite.
// for a more optimized build.
extendViteConfig((config) => {
config.build = config.build || {}
config.build.rollupOptions = config.build.rollupOptions || {}
config.build.rollupOptions.output = config.build.rollupOptions.output || {}

config.build.rollupOptions.output = {
...config.build.rollupOptions.output,
manualChunks: (id) => {
if (id.includes('/node_modules/swiper')) {
return 'swiper'
}
}
}
})

// Import Each Swiper Module & CSS if it exists.
for (const [key, _] of Object.entries(swiper)) {
// Turn key to snake-case.
Expand Down

0 comments on commit 9719628

Please sign in to comment.