question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundle Size / Nuxt: Why is vue-server-renderer included in Nuxt Frontend Build

See original GitHub issue

Bug 🐞

What is the current behavior?

Go to the folder examples/nuxt. Add the following script to package.json "analyze": "nuxt build --analyze"

This is the output: image


The vue-server-renderer with the size of 334KB is added to the frontend bundle!

What is the expected behavior?

vue-server-renderer/basic.js should not be part of the Frontend Build in nuxt.js. It is part of nuxt.js anyway and not used in the frontend.

Does this happen only in specific situations?

No it happens always. Even on the commited example.

What is the proposed solution?

I have no idea.

What is the version you are using?

4.8.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
reinolduscommented, Feb 10, 2021

I’ve looked through the code a bit and do not see any reason why webpack wouldn’t bundle vue-server-render. I guess this is the critical statement here:

try {
  _renderToString = require('vue-server-renderer/basic');
} catch (e) {
  // error is handled by regular if, in case it's `undefined`
}

I do not know how to fix it at the core, but I worked around it with some additional config:

In your nuxt config under build (https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build#extend):

extend(config, { isClient }) {
  // Extend only webpack config for client-bundle
  if (isClient) {
    config.plugins.push(
      new webpack.IgnorePlugin({
        checkResource(resource, context) {
          if (resource.includes('vue-server-renderer')) {
            return true
          }
          // do something with resource
          return false
        },
      })
    )
  }
},

The dependency is gone from the front-end and SSR still works.

Edit: I forgot to mention you also have to import webpack in your nuxt.config.js:

import webpack from 'webpack'

1reaction
ayaloncommented, Jan 20, 2021

Unfortunatly this does not work for me. On Nuxt I have to include AisInstantSearchSsr instead of AisInstantSearch . I tried to import it as you said but the bundle size is the same: import AisInstantSearchSsr from 'vue-instantsearch/es/src/components/InstantSearchSsr.js' As soon as I have this dependancy the build in frontend adds the view renderer. Any other ideas? These unneeded 334kb hurt so much in the frontend.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle Size / Nuxt: Why is vue-server-renderer included in Nuxt ...
What is the current behavior? Go to the folder examples/nuxt. Add the following script to package.json "analyze": "nuxt build --analyze". This ...
Read more >
Server-side rendering with Vue and Nuxt.js - LogRocket Blog
Learn about server-side rendering (SSR) and client-side rendering (CSR), how its evolved, and how to use implement it with Nuxt.js and Vue.
Read more >
Nuxt Server Side Rendering vs Pre-rendering
When using this method to build your app, Nuxt goes through each page in your project and renders them into an HTML file...
Read more >
Vue and Nuxt Performance Optimization Checklist
Find the size of any javascript package and its effect on your frontend bundle. Make sure to use libraries that support tree shaking...
Read more >
Server Side Rendering - Nuxt
Server -side sends a fully rendered page to the client; the client's JavaScript bundle takes over which then allows the Vue.js app to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found