Search code examples
vue.jsnuxt.jsbuildernuxt3.js

nuxt builder in nuxt3


Nuxt 2 was having builder which we used to build nuxt app.

But nuxt 3 is not having builder. Is that not part of nuxt 3? Following is what we were using in nuxt 2.

import { Builder } from '@nuxt/builder';

I am serving nuxt app from nestjs like following example of next.js.

https://github.com/hnviradiya/contact-list/blob/main/src/server/client-app/client-app.service.ts


Solution

  • Following is equivalent to Nuxt 2 code.

    import { NestFactory } from '@nestjs/core';
    import { AppModule } from './app.module.js';
    import { loadNuxt } from 'nuxt3';
    import { buildNuxt,  Resolver } from '@nuxt/kit';
    
    async function bootstrap() {
      const app = await NestFactory.create(AppModule);
    
      // Check if we need to run Nuxt in development mode
      const isDev = process.env.NODE_ENV !== 'production'
    
      // Get a ready to use Nuxt instance
      const nuxt = await loadNuxt({ rootDir: 'src/client-app/' })
    
      // Enable live build & reloading on dev
      if (isDev) {
        buildNuxt(nuxt)
      }
    
      await app.listen(3001);
    }
    bootstrap();