Nuxt.js: Build server-only bundle and skip client-bundle

Created on 12 Jan 2020  路  5Comments  路  Source: nuxt/nuxt.js

What problem does this feature solve?

I have a specific use-case, where I only render the pages on the server-side (using Nuxt programatically).

The build time would greatly decrease, if I could just skip building the client-bundle entirely.

feature-request

Most helpful comment

We have been talking with @pi0 and we could introduce build.client option in the nuxt.config.js:

// nuxt.config.js
export default {
  build: {
    client: false
  }
}

All 5 comments

Hi @kevcodez

So we agree that you don't need JavaScript at all on your generated pages?

@Atinux Yes. There is no further navigation or whatsoever. Let me elaborate on my specific use-case.

I have an express API, receiving a POST request with some data

{
  "template": "invoice",
  "data": {
    "firstName": "foo",
    "lastName": "bar"
  }
}

The endpoint then uses nuxt.renderRoute to dynamically render a page:

// Nuxt and express initialization

app.post('/generate', async (req, res, next) => {
  await nuxt.ready()
  const jsonRequest = req.body
  const route = '/' + jsonRequest.template
  const {
    html,
    _error,
    _redirected
  } = await nuxt.renderRoute(route, {
    data: jsonRequest.data
  })

  res.set('Content-Type', 'text/html')
  res.send(html)
})

The API will simply return the generated HTML. That generated HTML is then used to generate a PDF (via headless chrome).

The express API, using Nuxt internally, is deployed using serverless framework.

IMO, I do not need a client bundle since I only render the pages on the server side. This would greatly decrease build time, since I'd only build the server bundle (if possible).

Let me know if I am completely off here. Appreciate any input.

We have been talking with @pi0 and we could introduce build.client option in the nuxt.config.js:

// nuxt.config.js
export default {
  build: {
    client: false
  }
}

@Atinux that would be perfect!

@Atinux What is the status of this? And is there some way to prevent loading the bundle client side in the mean time?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadimsg picture vadimsg  路  3Comments

jaredreich picture jaredreich  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

maicong picture maicong  路  3Comments

mikekidder picture mikekidder  路  3Comments