Nuxt Rebundle
Nuxt Rebundle is an experimental Nuxt module designed to explore and implement advanced bundler optimizations for Nuxt applications. As of version 0.0.2, it is a 'work-in-progress laboratory,' focusing primarily on automatically splitting `useAsyncData` fetcher functions into asynchronous chunks. This feature is particularly beneficial for static site generation (SSG) scenarios to improve initial page load performance by deferring the loading of data-fetching logic until it's needed. Due to its early development stage, there is no predictable release cadence, and the module should be approached with caution as its API and internal workings are subject to frequent changes. Key differentiators include its tight integration with Nuxt's build process to automatically apply specific optimization patterns that might otherwise require complex manual configuration, though its feature set is currently limited to `useAsyncData` splitting.
Common errors
-
Module 'nuxt-rebundle' not found
cause The module was either not installed correctly, or its name is misspelled in `nuxt.config.ts`.fixEnsure you have run `npx nuxi@latest module add nuxt-rebundle` and that `modules: ['nuxt-rebundle']` is correctly present in your `nuxt.config.ts` file. -
Cannot use import statement outside a module
cause Attempting to `import` or `require` the module directly in a file that is not treated as an ES module, or in an incorrect context.fixNuxt modules are registered by string name in `nuxt.config.ts`. Avoid direct `import` or `require` statements for the `nuxt-rebundle` package in your application code.
Warnings
- gotcha This module is explicitly marked as a 'work-in-progress laboratory for exploring bundler optimisations in Nuxt.' It is not intended for production use without careful consideration and testing.
- breaking Due to its early development stage (version 0.0.2), frequent breaking changes in API, behavior, and underlying implementation are highly probable.
- gotcha The module's current feature set is limited to automatically splitting `useAsyncData` fetcher functions into async chunks. It does not provide other general bundler optimizations.
Install
-
npm install nuxt-rebundle -
yarn add nuxt-rebundle -
pnpm add nuxt-rebundle
Imports
- Module registration
import nuxtRebundle from 'nuxt-rebundle'; // This module does not expose direct programmatic exports for userland code.
export default defineNuxtConfig({ modules: ['nuxt-rebundle'], }); - CommonJS require
const RebundleModule = require('nuxt-rebundle');N/A (Nuxt 3 configurations are primarily ESM)
- Type Inference
import type { SomeRebundleType } from 'nuxt-rebundle';Nuxt handles module type inference automatically for registered modules.
Quickstart
npx nuxi@latest module add nuxt-rebundle
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt';
export default defineNuxtConfig({
modules: [
// Register the nuxt-rebundle module.
// Note: No configuration options are currently exposed or documented.
'nuxt-rebundle'
],
// Other Nuxt configuration...
devtools: { enabled: true }
});