Search code examples
vue.jsnuxt.jsvue-ssr

How to remove window._nuxt_ in nuxt project, it is too large for me


When I use nuxt to develop my project, I find some problems.

window.__NUXT__=(function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,_,$,aa, ..... code was too larger

can I remove it or use js file to replace it?


Solution

  • I have found a relatively perfect solution. I will share it with you here. You can also take a look at the website I developed using NUXT Sample Website

    The key is the hook function vue-renderer:ssr:context, you can set the context.nuxt = null to remove any data in window._NUXT_.

    But it is not work well, you have to add serverRender and routePath to window.nuxt

    // nuxt.config.js
    {
    ...,
    hooks: {
        'vue-renderer:ssr:context'(context) {
          const routePath = JSON.stringify(context.nuxt.routePath);
          context.nuxt = {serverRendered: true, routePath};
        }
      }
    }
    

    You can see the result at my site